diff --git a/.gitattributes b/.gitattributes index c69c6c8..624c649 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ /.github/ export-ignore /Build/ export-ignore +/Tests/ export-ignore /.editorconfig export-ignore /.gitattributes export-ignore /.gitlab-ci.yml export-ignore @@ -7,4 +8,4 @@ /crowdin.yml export-ignore /Makefile export-ignore /rector.php export-ignore -/shell.nix export-ignore \ No newline at end of file +/shell.nix export-ignore diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a720543..c32d1b1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,58 @@ jobs: tools: composer:v2 - name: PHP lint - run: "find *.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l" + run: Build/Scripts/lint-php.sh + + typoscript-linting: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.2" + tools: composer:v2 + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: TypoScript lint + run: Build/Scripts/lint-typoscript.sh + + xml-linting: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install xmllint + run: sudo apt-get update && sudo apt-get install -y libxml2-utils + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.2" + tools: composer:v2 + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: XML lint + run: Build/Scripts/lint-xml.sh + + yaml-linting: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install yamllint + run: pipx install yamllint + + - name: YAML lint + run: Build/Scripts/lint-yaml.sh documentation-rendering: runs-on: ubuntu-latest @@ -61,7 +112,7 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Coding Guideline - run: vendor/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --using-cache=no --path-mode=intersection ./ + run: Build/Scripts/cgl.sh code-quality: runs-on: ubuntu-latest @@ -71,13 +122,13 @@ jobs: matrix: include: - php-version: '8.2' - typo3-version: '^13.4' + typo3-version: '^14.3' - php-version: '8.3' - typo3-version: '^13.4' + typo3-version: '^14.3' - php-version: '8.4' - typo3-version: '^13.4' + typo3-version: '^14.3' - php-version: '8.5' - typo3-version: '^13.4' + typo3-version: '^14.3' steps: - uses: actions/checkout@v4 @@ -92,4 +143,34 @@ jobs: composer require --no-interaction --prefer-dist --no-progress "typo3/cms-core:${{ matrix.typo3-version }}" "typo3/cms-extbase:${{ matrix.typo3-version }}" "typo3/cms-frontend:${{ matrix.typo3-version }}" - name: Code Quality (by PHPStan) - run: vendor/bin/phpstan analyse -c Build/phpstan.neon + run: Build/Scripts/phpstan.sh + + tests-unit-and-functional: + runs-on: ubuntu-latest + needs: + - coding-guideline + - code-quality + strategy: + matrix: + php-version: + - 8.2 + - 8.3 + - 8.4 + - 8.5 + steps: + - uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php-version }}" + tools: composer:v2 + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run unit tests + run: Build/Scripts/phpunit.sh unit + + - name: Run functional tests + run: Build/Scripts/phpunit.sh functional diff --git a/.gitignore b/.gitignore index 074fa2d..78ffaec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.build +.Build composer.lock .php-cs-fixer.cache @@ -11,7 +11,6 @@ Documentation-GENERATED-temp/ .idea var/ -vendor/ phpunit.coverage.xml phpunit.report.xml \ No newline at end of file diff --git a/Build/.php-cs-fixer.dist.php b/Build/.php-cs-fixer.dist.php index 58818f6..e04f9fa 100644 --- a/Build/.php-cs-fixer.dist.php +++ b/Build/.php-cs-fixer.dist.php @@ -21,6 +21,7 @@ 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'declare_parentheses' => true, + 'declare_strict_types' => true, 'dir_constant' => true, 'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']], 'modernize_strpos' => true, diff --git a/Build/Scripts/cgl.sh b/Build/Scripts/cgl.sh new file mode 100755 index 0000000..460cd7e --- /dev/null +++ b/Build/Scripts/cgl.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# +# Checks the coding guidelines with php-cs-fixer. +# +# Usage: +# Build/Scripts/cgl.sh check only, fails on violations +# Build/Scripts/cgl.sh --fix fix the violations in place + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary php-cs-fixer + +FIXER_ARGS=(--config=Build/.php-cs-fixer.dist.php --using-cache=no) +if [ "${1:-}" = "--fix" ]; then + shift +else + FIXER_ARGS+=(-v --dry-run --diff) +fi + +runPhp "${BIN_DIR}/php-cs-fixer" fix "${FIXER_ARGS[@]}" "$@" diff --git a/Build/Scripts/common.sh b/Build/Scripts/common.sh new file mode 100644 index 0000000..9220642 --- /dev/null +++ b/Build/Scripts/common.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Shared setup for all scripts in Build/Scripts. +# +# This file is sourced, not executed. It changes to the project root, so every +# script behaves the same no matter from where it has been called, and it +# provides the defaults all scripts rely on. +# +# Environment variables used as overrides: +# PHP_BIN php binary to use, defaults to "php" +# PHP_MEMORY_LIMIT memory_limit for all php calls, defaults to "-1" + +set -euo pipefail + +PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +readonly PROJECT_ROOT +cd "${PROJECT_ROOT}" + +PHP_BIN="${PHP_BIN:-php}" +PHP_MEMORY_LIMIT="${PHP_MEMORY_LIMIT:--1}" +BIN_DIR="${PROJECT_ROOT}/.Build/bin" +readonly PHP_BIN PHP_MEMORY_LIMIT BIN_DIR + +# Runs php with the configured memory limit, independent of the php.ini in use. +runPhp() { + "${PHP_BIN}" -d memory_limit="${PHP_MEMORY_LIMIT}" "$@" +} + +# Fails with a readable message if composer install has not been run yet. +requireBinary() { + if [ ! -f "${BIN_DIR}/$1" ]; then + echo "Missing ${BIN_DIR}/$1, please run \"composer install\" first." >&2 + exit 1 + fi +} diff --git a/Build/Scripts/coverage.sh b/Build/Scripts/coverage.sh new file mode 100755 index 0000000..21e6452 --- /dev/null +++ b/Build/Scripts/coverage.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# +# Runs all phpunit tests and measures the code coverage of Classes/. +# +# Usage: +# Build/Scripts/coverage.sh [additional phpunit arguments] +# +# Every testsuite defined in Build/phpunit.xml.dist runs in its own phpunit +# process, like in phpunit.sh, the functional bootstrap leaks global state +# into the unit tests. The coverage of all suites is merged with phpcov, the +# summary is printed and the html report is written to +# .Build/coverage/index.html. +# +# Requirements: +# - php with xdebug or pcov +# +# Environment variables used as overrides: +# typo3DatabaseDriver database driver to test against, defaults to "pdo_sqlite" + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary phpunit +requireBinary phpcov + +if ! runPhp -r 'exit(extension_loaded("xdebug") || extension_loaded("pcov") ? 0 : 1);'; then + echo "Missing coverage driver, please enable xdebug or pcov." >&2 + exit 1 +fi + +export typo3DatabaseDriver="${typo3DatabaseDriver:-pdo_sqlite}" +export XDEBUG_MODE=coverage + +COVERAGE_PATH="${PROJECT_ROOT}/.Build/coverage" +COVERAGE_DATA_PATH="${COVERAGE_PATH}/data" +rm -rf "${COVERAGE_PATH}" +mkdir -p "${COVERAGE_DATA_PATH}" + +mapfile -t SUITES < <(runPhp "${BIN_DIR}/phpunit" -c Build/phpunit.xml.dist --list-suites \ + | sed -n 's/^ - \(.*\) ([0-9]\{1,\} tests\{0,1\})$/\1/p') + +if [ ${#SUITES[@]} -eq 0 ]; then + echo "No testsuites found in Build/phpunit.xml.dist." >&2 + exit 1 +fi + +STATUS=0 +for suite in "${SUITES[@]}"; do + echo "Running testsuite \"${suite}\" ..." + runPhp "${BIN_DIR}/phpunit" \ + -c Build/phpunit.xml.dist \ + --testsuite "${suite}" \ + --coverage-php "${COVERAGE_DATA_PATH}/${suite}.cov" \ + "$@" || STATUS=$? +done + +runPhp "${BIN_DIR}/phpcov" merge \ + --text php://stdout \ + --html "${COVERAGE_PATH}" \ + "${COVERAGE_DATA_PATH}" + +echo "HTML report: ${COVERAGE_PATH}/index.html" + +exit "${STATUS}" diff --git a/Build/Scripts/lint-php.sh b/Build/Scripts/lint-php.sh new file mode 100755 index 0000000..1b86352 --- /dev/null +++ b/Build/Scripts/lint-php.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# +# Lints all php files of the extension for syntax errors. +# +# Usage: +# Build/Scripts/lint-php.sh + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +find ./*.php Classes Configuration Tests -name '*.php' -print0 \ + | xargs -0 -n 1 -P 4 "${PHP_BIN}" -l diff --git a/Build/Scripts/lint-typoscript.sh b/Build/Scripts/lint-typoscript.sh new file mode 100755 index 0000000..d564292 --- /dev/null +++ b/Build/Scripts/lint-typoscript.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# Lints all TypoScript and TSconfig files of the extension with +# helmich/typo3-typoscript-lint, using Build/typoscriptlint.yaml. +# Warnings fail the lint as well. +# +# Usage: +# Build/Scripts/lint-typoscript.sh + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary typoscript-lint + +paths=() +for path in Configuration Tests ext_typoscript_setup.typoscript; do + if [ -e "${path}" ]; then + paths+=("${path}") + fi +done + +runPhp "${BIN_DIR}/typoscript-lint" --config Build/typoscriptlint.yaml --fail-on-warnings "${paths[@]}" diff --git a/Build/Scripts/lint-xml.sh b/Build/Scripts/lint-xml.sh new file mode 100755 index 0000000..06b4e08 --- /dev/null +++ b/Build/Scripts/lint-xml.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# Validates the xml files of the extension against their schemas: +# - XLIFF files in Resources/Private/Language against XLIFF 1.2 strict +# (Build/xliff-core-1.2-strict.xsd, imports Build/xml.xsd) +# - Build/phpunit.xml.dist against the schema of the installed PHPUnit +# +# xmllint is not installed via composer. It is provided by shell.nix, in CI it +# is installed via apt (libxml2-utils). +# +# Usage: +# Build/Scripts/lint-xml.sh + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +if ! command -v xmllint > /dev/null; then + echo "Missing xmllint, please install it first, e.g. the package libxml2-utils." >&2 + exit 1 +fi +requireBinary phpunit + +if [ -d Resources/Private/Language ]; then + find Resources/Private/Language -name '*.xlf' -print0 \ + | xargs -0 -r xmllint --schema Build/xliff-core-1.2-strict.xsd --noout +fi + +xmllint --schema .Build/vendor/phpunit/phpunit/phpunit.xsd --noout Build/phpunit.xml.dist diff --git a/Build/Scripts/lint-yaml.sh b/Build/Scripts/lint-yaml.sh new file mode 100755 index 0000000..1eaf223 --- /dev/null +++ b/Build/Scripts/lint-yaml.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# +# Lints all yaml files of the extension with yamllint, using +# Build/yamllint.yaml. Files ignored by .gitignore are skipped. +# +# yamllint is not installed via composer. It is provided by shell.nix, in CI it +# is installed via pipx. +# +# Usage: +# Build/Scripts/lint-yaml.sh + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +if ! command -v yamllint > /dev/null; then + echo "Missing yamllint, please install it first, e.g. \"pipx install yamllint\"." >&2 + exit 1 +fi + +yamllint --config-file Build/yamllint.yaml . diff --git a/Build/Scripts/phpstan.sh b/Build/Scripts/phpstan.sh new file mode 100755 index 0000000..6f06604 --- /dev/null +++ b/Build/Scripts/phpstan.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# +# Runs the static code analysis with phpstan. +# +# Usage: +# Build/Scripts/phpstan.sh [additional phpstan arguments] + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary phpstan + +runPhp "${BIN_DIR}/phpstan" analyse -c Build/phpstan.neon "$@" diff --git a/Build/Scripts/phpunit.sh b/Build/Scripts/phpunit.sh new file mode 100755 index 0000000..2636b97 --- /dev/null +++ b/Build/Scripts/phpunit.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# +# Runs the phpunit tests. +# +# Usage: +# Build/Scripts/phpunit.sh [testsuite] [additional phpunit arguments] +# +# Without a testsuite every suite defined in Build/phpunit.xml.dist is run, +# each one in its own phpunit process. They cannot share a process, the +# functional bootstrap leaks global state into the unit tests. The first +# argument is taken as the testsuite name unless it starts with a dash. +# +# Environment variables used as overrides: +# typo3DatabaseDriver database driver to test against, defaults to "pdo_sqlite" + +source "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +requireBinary phpunit + +export typo3DatabaseDriver="${typo3DatabaseDriver:-pdo_sqlite}" + +runSuite() { + local suite="$1" + shift + + runPhp "${BIN_DIR}/phpunit" \ + -c Build/phpunit.xml.dist \ + --testsuite "${suite}" \ + --display-warnings \ + --display-deprecations \ + --display-errors \ + --display-notices \ + "$@" +} + +if [ $# -gt 0 ] && [ -n "$1" ] && [ "${1:0:1}" != "-" ]; then + TESTSUITE="$1" + shift + runSuite "${TESTSUITE}" "$@" + exit $? +fi + +mapfile -t SUITES < <(runPhp "${BIN_DIR}/phpunit" -c Build/phpunit.xml.dist --list-suites \ + | sed -n 's/^ - \(.*\) ([0-9]\{1,\} tests\{0,1\})$/\1/p') + +if [ ${#SUITES[@]} -eq 0 ]; then + echo "No testsuites found in Build/phpunit.xml.dist." >&2 + exit 1 +fi + +STATUS=0 +for suite in "${SUITES[@]}"; do + echo "Running testsuite \"${suite}\" ..." + runSuite "${suite}" "$@" || STATUS=$? +done + +exit "${STATUS}" diff --git a/Build/phpstan.neon b/Build/phpstan.neon index 871d987..30b0b9a 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -5,5 +5,5 @@ parameters: paths: - ../Classes - ../Configuration - - ../ext_emconf.php + - ../Tests - ../ext_localconf.php diff --git a/Build/phpunit.xml.dist b/Build/phpunit.xml.dist new file mode 100644 index 0000000..37fceac --- /dev/null +++ b/Build/phpunit.xml.dist @@ -0,0 +1,33 @@ + + + + + + ../Tests/Functional/ + + + ../Tests/Unit/ + + + + + ../Classes/ + + + diff --git a/Build/typoscriptlint.yaml b/Build/typoscriptlint.yaml index 12405ea..6b7e404 100644 --- a/Build/typoscriptlint.yaml +++ b/Build/typoscriptlint.yaml @@ -3,17 +3,18 @@ sniffs: parameters: useSpaces: true indentPerLevel: 4 - indentConditions: false + indentConditions: true - class: DeadCode - class: OperatorWhitespace + # Values like validator names or paths are repeated on purpose. Moving them + # to constants would add them to the public configuration of the extension. - class: RepeatingRValue - parameters: - allowedRightValues: - - "TYPO3\\CMS\\Frontend\\DataProcessing\\DatabaseQueryProcessor" + disabled: true - class: DuplicateAssignment - class: EmptySection - class: NestingConsistency parameters: commonPathPrefixThreshold: 1 filePatterns: - - "*.typoscript" \ No newline at end of file + - "*.typoscript" + - "*.tsconfig" diff --git a/Build/xliff-core-1.2-strict.xsd b/Build/xliff-core-1.2-strict.xsd new file mode 100644 index 0000000..b9b2392 --- /dev/null +++ b/Build/xliff-core-1.2-strict.xsd @@ -0,0 +1,2223 @@ + + + + + + + + + + + + + + + Values for the attribute 'context-type'. + + + + + Indicates a database content. + + + + + Indicates the content of an element within an XML document. + + + + + Indicates the name of an element within an XML document. + + + + + Indicates the line number from the sourcefile (see context-type="sourcefile") where the <source> is found. + + + + + Indicates a the number of parameters contained within the <source>. + + + + + Indicates notes pertaining to the parameters in the <source>. + + + + + Indicates the content of a record within a database. + + + + + Indicates the name of a record within a database. + + + + + Indicates the original source file in the case that multiple files are merged to form the original file from which the XLIFF file is created. This differs from the original <file> attribute in that this sourcefile is one of many that make up that file. + + + + + + + Values for the attribute 'count-type'. + + + + + Indicates the count units are items that are used X times in a certain context; example: this is a reusable text unit which is used 42 times in other texts. + + + + + Indicates the count units are translation units existing already in the same document. + + + + + Indicates a total count. + + + + + + + Values for the attribute 'ctype' when used other elements than <ph> or <x>. + + + + + Indicates a run of bolded text. + + + + + Indicates a run of text in italics. + + + + + Indicates a run of underlined text. + + + + + Indicates a run of hyper-text. + + + + + + + Values for the attribute 'ctype' when used with <ph> or <x>. + + + + + Indicates a inline image. + + + + + Indicates a page break. + + + + + Indicates a line break. + + + + + + + + + + + + Values for the attribute 'datatype'. + + + + + Indicates Active Server Page data. + + + + + Indicates C source file data. + + + + + Indicates Channel Definition Format (CDF) data. + + + + + Indicates ColdFusion data. + + + + + Indicates C++ source file data. + + + + + Indicates C-Sharp data. + + + + + Indicates strings from C, ASM, and driver files data. + + + + + Indicates comma-separated values data. + + + + + Indicates database data. + + + + + Indicates portions of document that follows data and contains metadata. + + + + + Indicates portions of document that precedes data and contains metadata. + + + + + Indicates data from standard UI file operations dialogs (e.g., Open, Save, Save As, Export, Import). + + + + + Indicates standard user input screen data. + + + + + Indicates HyperText Markup Language (HTML) data - document instance. + + + + + Indicates content within an HTML document’s <body> element. + + + + + Indicates Windows INI file data. + + + + + Indicates Interleaf data. + + + + + Indicates Java source file data (extension '.java'). + + + + + Indicates Java property resource bundle data. + + + + + Indicates Java list resource bundle data. + + + + + Indicates JavaScript source file data. + + + + + Indicates JScript source file data. + + + + + Indicates information relating to formatting. + + + + + Indicates LISP source file data. + + + + + Indicates information relating to margin formats. + + + + + Indicates a file containing menu. + + + + + Indicates numerically identified string table. + + + + + Indicates Maker Interchange Format (MIF) data. + + + + + Indicates that the datatype attribute value is a MIME Type value and is defined in the mime-type attribute. + + + + + Indicates GNU Machine Object data. + + + + + Indicates Message Librarian strings created by Novell's Message Librarian Tool. + + + + + Indicates information to be displayed at the bottom of each page of a document. + + + + + Indicates information to be displayed at the top of each page of a document. + + + + + Indicates a list of property values (e.g., settings within INI files or preferences dialog). + + + + + Indicates Pascal source file data. + + + + + Indicates Hypertext Preprocessor data. + + + + + Indicates plain text file (no formatting other than, possibly, wrapping). + + + + + Indicates GNU Portable Object file. + + + + + Indicates dynamically generated user defined document. e.g. Oracle Report, Crystal Report, etc. + + + + + Indicates Windows .NET binary resources. + + + + + Indicates Windows .NET Resources. + + + + + Indicates Rich Text Format (RTF) data. + + + + + Indicates Standard Generalized Markup Language (SGML) data - document instance. + + + + + Indicates Standard Generalized Markup Language (SGML) data - Document Type Definition (DTD). + + + + + Indicates Scalable Vector Graphic (SVG) data. + + + + + Indicates VisualBasic Script source file. + + + + + Indicates warning message. + + + + + Indicates Windows (Win32) resources (i.e. resources extracted from an RC script, a message file, or a compiled file). + + + + + Indicates Extensible HyperText Markup Language (XHTML) data - document instance. + + + + + Indicates Extensible Markup Language (XML) data - document instance. + + + + + Indicates Extensible Markup Language (XML) data - Document Type Definition (DTD). + + + + + Indicates Extensible Stylesheet Language (XSL) data. + + + + + Indicates XUL elements. + + + + + + + Values for the attribute 'mtype'. + + + + + Indicates the marked text is an abbreviation. + + + + + ISO-12620 2.1.8: A term resulting from the omission of any part of the full term while designating the same concept. + + + + + ISO-12620 2.1.8.1: An abbreviated form of a simple term resulting from the omission of some of its letters (e.g. 'adj.' for 'adjective'). + + + + + ISO-12620 2.1.8.4: An abbreviated form of a term made up of letters from the full form of a multiword term strung together into a sequence pronounced only syllabically (e.g. 'radar' for 'radio detecting and ranging'). + + + + + ISO-12620: A proper-name term, such as the name of an agency or other proper entity. + + + + + ISO-12620 2.1.18.1: A recurrent word combination characterized by cohesion in that the components of the collocation must co-occur within an utterance or series of utterances, even though they do not necessarily have to maintain immediate proximity to one another. + + + + + ISO-12620 2.1.5: A synonym for an international scientific term that is used in general discourse in a given language. + + + + + Indicates the marked text is a date and/or time. + + + + + ISO-12620 2.1.15: An expression used to represent a concept based on a statement that two mathematical expressions are, for instance, equal as identified by the equal sign (=), or assigned to one another by a similar sign. + + + + + ISO-12620 2.1.7: The complete representation of a term for which there is an abbreviated form. + + + + + ISO-12620 2.1.14: Figures, symbols or the like used to express a concept briefly, such as a mathematical or chemical formula. + + + + + ISO-12620 2.1.1: The concept designation that has been chosen to head a terminological record. + + + + + ISO-12620 2.1.8.3: An abbreviated form of a term consisting of some of the initial letters of the words making up a multiword term or the term elements making up a compound term when these letters are pronounced individually (e.g. 'BSE' for 'bovine spongiform encephalopathy'). + + + + + ISO-12620 2.1.4: A term that is part of an international scientific nomenclature as adopted by an appropriate scientific body. + + + + + ISO-12620 2.1.6: A term that has the same or nearly identical orthographic or phonemic form in many languages. + + + + + ISO-12620 2.1.16: An expression used to represent a concept based on mathematical or logical relations, such as statements of inequality, set relationships, Boolean operations, and the like. + + + + + ISO-12620 2.1.17: A unit to track object. + + + + + Indicates the marked text is a name. + + + + + ISO-12620 2.1.3: A term that represents the same or a very similar concept as another term in the same language, but for which interchangeability is limited to some contexts and inapplicable in others. + + + + + ISO-12620 2.1.17.2: A unique alphanumeric designation assigned to an object in a manufacturing system. + + + + + Indicates the marked text is a phrase. + + + + + ISO-12620 2.1.18: Any group of two or more words that form a unit, the meaning of which frequently cannot be deduced based on the combined sense of the words making up the phrase. + + + + + Indicates the marked text should not be translated. + + + + + ISO-12620 2.1.12: A form of a term resulting from an operation whereby non-Latin writing systems are converted to the Latin alphabet. + + + + + Indicates that the marked text represents a segment. + + + + + ISO-12620 2.1.18.2: A fixed, lexicalized phrase. + + + + + ISO-12620 2.1.8.2: A variant of a multiword term that includes fewer words than the full form of the term (e.g. 'Group of Twenty-four' for 'Intergovernmental Group of Twenty-four on International Monetary Affairs'). + + + + + ISO-12620 2.1.17.1: Stock keeping unit, an inventory item identified by a unique alphanumeric designation assigned to an object in an inventory control system. + + + + + ISO-12620 2.1.19: A fixed chunk of recurring text. + + + + + ISO-12620 2.1.13: A designation of a concept by letters, numerals, pictograms or any combination thereof. + + + + + ISO-12620 2.1.2: Any term that represents the same or a very similar concept as the main entry term in a term entry. + + + + + ISO-12620 2.1.18.3: Phraseological unit in a language that expresses the same semantic content as another phrase in that same language. + + + + + Indicates the marked text is a term. + + + + + ISO-12620 2.1.11: A form of a term resulting from an operation whereby the characters of one writing system are represented by characters from another writing system, taking into account the pronunciation of the characters converted. + + + + + ISO-12620 2.1.10: A form of a term resulting from an operation whereby the characters of an alphabetic writing system are represented by characters from another alphabetic writing system. + + + + + ISO-12620 2.1.8.5: An abbreviated form of a term resulting from the omission of one or more term elements or syllables (e.g. 'flu' for 'influenza'). + + + + + ISO-12620 2.1.9: One of the alternate forms of a term. + + + + + + + Values for the attribute 'restype'. + + + + + Indicates a Windows RC AUTO3STATE control. + + + + + Indicates a Windows RC AUTOCHECKBOX control. + + + + + Indicates a Windows RC AUTORADIOBUTTON control. + + + + + Indicates a Windows RC BEDIT control. + + + + + Indicates a bitmap, for example a BITMAP resource in Windows. + + + + + Indicates a button object, for example a BUTTON control Windows. + + + + + Indicates a caption, such as the caption of a dialog box. + + + + + Indicates the cell in a table, for example the content of the <td> element in HTML. + + + + + Indicates check box object, for example a CHECKBOX control in Windows. + + + + + Indicates a menu item with an associated checkbox. + + + + + Indicates a list box, but with a check-box for each item. + + + + + Indicates a color selection dialog. + + + + + Indicates a combination of edit box and listbox object, for example a COMBOBOX control in Windows. + + + + + Indicates an initialization entry of an extended combobox DLGINIT resource block. (code 0x1234). + + + + + Indicates an initialization entry of a combobox DLGINIT resource block (code 0x0403). + + + + + Indicates a UI base class element that cannot be represented by any other element. + + + + + Indicates a context menu. + + + + + Indicates a Windows RC CTEXT control. + + + + + Indicates a cursor, for example a CURSOR resource in Windows. + + + + + Indicates a date/time picker. + + + + + Indicates a Windows RC DEFPUSHBUTTON control. + + + + + Indicates a dialog box. + + + + + Indicates a Windows RC DLGINIT resource block. + + + + + Indicates an edit box object, for example an EDIT control in Windows. + + + + + Indicates a filename. + + + + + Indicates a file dialog. + + + + + Indicates a footnote. + + + + + Indicates a font name. + + + + + Indicates a footer. + + + + + Indicates a frame object. + + + + + Indicates a XUL grid element. + + + + + Indicates a groupbox object, for example a GROUPBOX control in Windows. + + + + + Indicates a header item. + + + + + Indicates a heading, such has the content of <h1>, <h2>, etc. in HTML. + + + + + Indicates a Windows RC HEDIT control. + + + + + Indicates a horizontal scrollbar. + + + + + Indicates an icon, for example an ICON resource in Windows. + + + + + Indicates a Windows RC IEDIT control. + + + + + Indicates keyword list, such as the content of the Keywords meta-data in HTML, or a K footnote in WinHelp RTF. + + + + + Indicates a label object. + + + + + Indicates a label that is also a HTML link (not necessarily a URL). + + + + + Indicates a list (a group of list-items, for example an <ol> or <ul> element in HTML). + + + + + Indicates a listbox object, for example an LISTBOX control in Windows. + + + + + Indicates an list item (an entry in a list). + + + + + Indicates a Windows RC LTEXT control. + + + + + Indicates a menu (a group of menu-items). + + + + + Indicates a toolbar containing one or more tope level menus. + + + + + Indicates a menu item (an entry in a menu). + + + + + Indicates a XUL menuseparator element. + + + + + Indicates a message, for example an entry in a MESSAGETABLE resource in Windows. + + + + + Indicates a calendar control. + + + + + Indicates an edit box beside a spin control. + + + + + Indicates a catch all for rectangular areas. + + + + + Indicates a standalone menu not necessarily associated with a menubar. + + + + + Indicates a pushbox object, for example a PUSHBOX control in Windows. + + + + + Indicates a Windows RC PUSHBUTTON control. + + + + + Indicates a radio button object. + + + + + Indicates a menuitem with associated radio button. + + + + + Indicates raw data resources for an application. + + + + + Indicates a row in a table. + + + + + Indicates a Windows RC RTEXT control. + + + + + Indicates a user navigable container used to show a portion of a document. + + + + + Indicates a generic divider object (e.g. menu group separator). + + + + + Windows accelerators, shortcuts in resource or property files. + + + + + Indicates a UI control to indicate process activity but not progress. + + + + + Indicates a splitter bar. + + + + + Indicates a Windows RC STATE3 control. + + + + + Indicates a window for providing feedback to the users, like 'read-only', etc. + + + + + Indicates a string, for example an entry in a STRINGTABLE resource in Windows. + + + + + Indicates a layers of controls with a tab to select layers. + + + + + Indicates a display and edits regular two-dimensional tables of cells. + + + + + Indicates a XUL textbox element. + + + + + Indicates a UI button that can be toggled to on or off state. + + + + + Indicates an array of controls, usually buttons. + + + + + Indicates a pop up tool tip text. + + + + + Indicates a bar with a pointer indicating a position within a certain range. + + + + + Indicates a control that displays a set of hierarchical data. + + + + + Indicates a URI (URN or URL). + + + + + Indicates a Windows RC USERBUTTON control. + + + + + Indicates a user-defined control like CONTROL control in Windows. + + + + + Indicates the text of a variable. + + + + + Indicates version information about a resource like VERSIONINFO in Windows. + + + + + Indicates a vertical scrollbar. + + + + + Indicates a graphical window. + + + + + + + Values for the attribute 'size-unit'. + + + + + Indicates a size in 8-bit bytes. + + + + + Indicates a size in Unicode characters. + + + + + Indicates a size in columns. Used for HTML text area. + + + + + Indicates a size in centimeters. + + + + + Indicates a size in dialog units, as defined in Windows resources. + + + + + Indicates a size in 'font-size' units (as defined in CSS). + + + + + Indicates a size in 'x-height' units (as defined in CSS). + + + + + Indicates a size in glyphs. A glyph is considered to be one or more combined Unicode characters that represent a single displayable text character. Sometimes referred to as a 'grapheme cluster' + + + + + Indicates a size in inches. + + + + + Indicates a size in millimeters. + + + + + Indicates a size in percentage. + + + + + Indicates a size in pixels. + + + + + Indicates a size in point. + + + + + Indicates a size in rows. Used for HTML text area. + + + + + + + Values for the attribute 'state'. + + + + + Indicates the terminating state. + + + + + Indicates only non-textual information needs adaptation. + + + + + Indicates both text and non-textual information needs adaptation. + + + + + Indicates only non-textual information needs review. + + + + + Indicates both text and non-textual information needs review. + + + + + Indicates that only the text of the item needs to be reviewed. + + + + + Indicates that the item needs to be translated. + + + + + Indicates that the item is new. For example, translation units that were not in a previous version of the document. + + + + + Indicates that changes are reviewed and approved. + + + + + Indicates that the item has been translated. + + + + + + + Values for the attribute 'state-qualifier'. + + + + + Indicates an exact match. An exact match occurs when a source text of a segment is exactly the same as the source text of a segment that was translated previously. + + + + + Indicates a fuzzy match. A fuzzy match occurs when a source text of a segment is very similar to the source text of a segment that was translated previously (e.g. when the difference is casing, a few changed words, white-space discripancy, etc.). + + + + + Indicates a match based on matching IDs (in addition to matching text). + + + + + Indicates a translation derived from a glossary. + + + + + Indicates a translation derived from existing translation. + + + + + Indicates a translation derived from machine translation. + + + + + Indicates a translation derived from a translation repository. + + + + + Indicates a translation derived from a translation memory. + + + + + Indicates the translation is suggested by machine translation. + + + + + Indicates that the item has been rejected because of incorrect grammar. + + + + + Indicates that the item has been rejected because it is incorrect. + + + + + Indicates that the item has been rejected because it is too long or too short. + + + + + Indicates that the item has been rejected because of incorrect spelling. + + + + + Indicates the translation is suggested by translation memory. + + + + + + + Values for the attribute 'unit'. + + + + + Refers to words. + + + + + Refers to pages. + + + + + Refers to <trans-unit> elements. + + + + + Refers to <bin-unit> elements. + + + + + Refers to glyphs. + + + + + Refers to <trans-unit> and/or <bin-unit> elements. + + + + + Refers to the occurrences of instances defined by the count-type value. + + + + + Refers to characters. + + + + + Refers to lines. + + + + + Refers to sentences. + + + + + Refers to paragraphs. + + + + + Refers to segments. + + + + + Refers to placeables (inline elements). + + + + + + + Values for the attribute 'priority'. + + + + + Highest priority. + + + + + High priority. + + + + + High priority, but not as important as 2. + + + + + High priority, but not as important as 3. + + + + + Medium priority, but more important than 6. + + + + + Medium priority, but less important than 5. + + + + + Low priority, but more important than 8. + + + + + Low priority, but more important than 9. + + + + + Low priority. + + + + + Lowest priority. + + + + + + + + + This value indicates that all properties can be reformatted. This value must be used alone. + + + + + This value indicates that no properties should be reformatted. This value must be used alone. + + + + + + + + + + + + + This value indicates that all information in the coord attribute can be modified. + + + + + This value indicates that the x information in the coord attribute can be modified. + + + + + This value indicates that the y information in the coord attribute can be modified. + + + + + This value indicates that the cx information in the coord attribute can be modified. + + + + + This value indicates that the cy information in the coord attribute can be modified. + + + + + This value indicates that all the information in the font attribute can be modified. + + + + + This value indicates that the name information in the font attribute can be modified. + + + + + This value indicates that the size information in the font attribute can be modified. + + + + + This value indicates that the weight information in the font attribute can be modified. + + + + + This value indicates that the information in the css-style attribute can be modified. + + + + + This value indicates that the information in the style attribute can be modified. + + + + + This value indicates that the information in the exstyle attribute can be modified. + + + + + + + + + + + + + Indicates that the context is informational in nature, specifying for example, how a term should be translated. Thus, should be displayed to anyone editing the XLIFF document. + + + + + Indicates that the context-group is used to specify where the term was found in the translatable source. Thus, it is not displayed. + + + + + Indicates that the context information should be used during translation memory lookups. Thus, it is not displayed. + + + + + + + + + Represents a translation proposal from a translation memory or other resource. + + + + + Represents a previous version of the target element. + + + + + Represents a rejected version of the target element. + + + + + Represents a translation to be used for reference purposes only, for example from a related product or a different language. + + + + + Represents a proposed translation that was used for the translation of the trans-unit, possibly modified. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Values for the attribute 'coord'. + + + + + + + + Version values: 1.0 and 1.1 are allowed for backward compatibility. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Build/xml.xsd b/Build/xml.xsd new file mode 100644 index 0000000..aea7d0d --- /dev/null +++ b/Build/xml.xsd @@ -0,0 +1,287 @@ + + + + + + +
+

About the XML namespace

+ +
+

+ This schema document describes the XML namespace, in a form + suitable for import by other schema documents. +

+

+ See + http://www.w3.org/XML/1998/namespace.html and + + http://www.w3.org/TR/REC-xml for information + about this namespace. +

+

+ Note that local names in this namespace are intended to be + defined only by the World Wide Web Consortium or its subgroups. + The names currently defined in this namespace are listed below. + They should not be used with conflicting semantics by any Working + Group, specification, or document instance. +

+

+ See further below in this document for more information about how to refer to this schema document from your own + XSD schema documents and about the + namespace-versioning policy governing this schema document. +

+
+
+
+
+ + + + +
+ +

lang (as an attribute name)

+

+ denotes an attribute whose value + is a language code for the natural language of the content of + any element; its value is inherited. This name is reserved + by virtue of its definition in the XML specification.

+ +
+
+

Notes

+

+ Attempting to install the relevant ISO 2- and 3-letter + codes as the enumerated possible values is probably never + going to be a realistic possibility. +

+

+ See BCP 47 at + http://www.rfc-editor.org/rfc/bcp/bcp47.txt + and the IANA language subtag registry at + + http://www.iana.org/assignments/language-subtag-registry + for further information. +

+

+ The union allows for the 'un-declaration' of xml:lang with + the empty string. +

+
+
+
+ + + + + + + + + +
+ + + + +
+ +

space (as an attribute name)

+

+ denotes an attribute whose + value is a keyword indicating what whitespace processing + discipline is intended for the content of the element; its + value is inherited. This name is reserved by virtue of its + definition in the XML specification.

+ +
+
+
+ + + + + + +
+ + + +
+ +

base (as an attribute name)

+

+ denotes an attribute whose value + provides a URI to be used as the base for interpreting any + relative URIs in the scope of the element on which it + appears; its value is inherited. This name is reserved + by virtue of its definition in the XML Base specification.

+ +

+ See http://www.w3.org/TR/xmlbase/ + for information about this attribute. +

+
+
+
+
+ + + + +
+ +

id (as an attribute name)

+

+ denotes an attribute whose value + should be interpreted as if declared to be of type ID. + This name is reserved by virtue of its definition in the + xml:id specification.

+ +

+ See http://www.w3.org/TR/xml-id/ + for information about this attribute. +

+
+
+
+
+ + + + + + + + + + +
+ +

Father (in any context at all)

+ +
+

+ denotes Jon Bosak, the chair of + the original XML Working Group. This name is reserved by + the following decision of the W3C XML Plenary and + XML Coordination groups: +

+
+

+ In appreciation for his vision, leadership and + dedication the W3C XML Plenary on this 10th day of + February, 2000, reserves for Jon Bosak in perpetuity + the XML name "xml:Father". +

+
+
+
+
+
+ + + +
+

About this schema document

+ +
+

+ This schema defines attributes and an attribute group suitable + for use by schemas wishing to allow xml:base, + xml:lang, xml:space or + xml:id attributes on elements they define. +

+

+ To enable this, such a schema must import this schema for + the XML namespace, e.g. as follows: +

+
+          <schema . . .>
+           . . .
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+     
+

+ or +

+
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+     
+

+ Subsequently, qualified reference to any of the attributes or the + group defined below will have the desired effect, e.g. +

+
+          <type . . .>
+           . . .
+           <attributeGroup ref="xml:specialAttrs"/>
+     
+

+ will define a type which will schema-validate an instance element + with any of those attributes. +

+
+
+
+
+ + + +
+

Versioning policy for this schema document

+
+

+ In keeping with the XML Schema WG's standard versioning + policy, this schema document will persist at + + http://www.w3.org/2009/01/xml.xsd. +

+

+ At the date of issue it can also be found at + + http://www.w3.org/2001/xml.xsd. +

+

+ The schema document at that URI may however change in the future, + in order to remain compatible with the latest version of XML + Schema itself, or with the XML namespace itself. In other words, + if the XML Schema or XML namespaces change, the version of this + document at + http://www.w3.org/2001/xml.xsd + + will change accordingly; the version at + + http://www.w3.org/2009/01/xml.xsd + + will not change. +

+

+ Previous dated (and unchanging) versions of this schema + document are at: +

+ +
+
+
+
+ +
+ diff --git a/Build/yamllint.yaml b/Build/yamllint.yaml index 5b0f71b..b8875c1 100644 --- a/Build/yamllint.yaml +++ b/Build/yamllint.yaml @@ -1,5 +1,7 @@ extends: default +ignore-from-file: .gitignore + rules: line-length: disable document-start: disable @@ -20,4 +22,6 @@ rules: forbid-in-block-mappings: true forbid-in-flow-mappings: true indentation: - spaces: 2 \ No newline at end of file + spaces: 2 + truthy: + check-keys: false diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index b484f5e..722fcd8 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -1,5 +1,7 @@ sendOkStatus(); - return $this->htmlResponse(); + return $this->htmlResponse(''); } private function updatePaymentAndTransaction($notify, Item $orderItem, string $status): bool diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index ab4650c..f24ceab 100644 --- a/Classes/EventListener/Order/Payment/ClearCart.php +++ b/Classes/EventListener/Order/Payment/ClearCart.php @@ -11,10 +11,10 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface; use Extcode\Cart\Domain\Model\Order\BillingAddress; use Extcode\Cart\Domain\Model\Order\ShippingAddress; use Extcode\Cart\Event\Order\PaymentEvent; -use Extcode\Cart\Service\PaymentMethodsServiceInterface; use Extcode\Cart\Service\SessionHandler; use Extcode\Cart\Utility\CartUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -23,7 +23,7 @@ class ClearCart { public function __construct( protected readonly CartUtility $cartUtility, - protected readonly PaymentMethodsServiceInterface $paymentMethodsService, + protected readonly PaymentMethodsLoaderInterface $paymentMethodsLoader, protected readonly SessionHandler $sessionHandler ) {} @@ -39,13 +39,9 @@ public function __invoke(PaymentEvent $event): void $paymentId = $cart->getPayment()->getId(); - if (!method_exists($this->paymentMethodsService, 'getConfigurationsForType')) { - return; - } - - $paymentSettings = $this->paymentMethodsService->getConfigurationsForType('payments', $cart->getBillingCountry()); + $paymentMethod = $this->paymentMethodsLoader->getPaymentMethods($cart)[$paymentId] ?? null; - if ((int)($paymentSettings['options'][$paymentId]['preventClearCart'] ?? 0) != 1) { + if ((int)($paymentMethod?->getConfig()['preventClearCart'] ?? 0) !== 1) { $cartPid = $settings['settings']['cart']['pid']; $this->sessionHandler->writeCart( diff --git a/Classes/EventListener/Order/Payment/ProviderRedirect.php b/Classes/EventListener/Order/Payment/ProviderRedirect.php index ad1ed96..16377a0 100644 --- a/Classes/EventListener/Order/Payment/ProviderRedirect.php +++ b/Classes/EventListener/Order/Payment/ProviderRedirect.php @@ -76,7 +76,7 @@ public function __invoke(PaymentEvent $event): void $payment = $this->orderItem->getPayment(); $provider = $payment->getProvider(); - [$provider, $clearingType] = explode('_', (string)$provider); + [$provider, $clearingType] = array_pad(explode('_', (string)$provider), 2, ''); if ($provider !== 'GIROSOLUTION') { return; diff --git a/Configuration/Services.php b/Configuration/Services.php index c3e4176..1e7d972 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -4,28 +4,51 @@ namespace Extcode\CartGirosolution\Configuration; +use Extcode\Cart\Event\Order\PaymentEvent; +use Extcode\Cart\EventListener\Order\Finish\Email; +use Extcode\CartGirosolution\Event\Order\FinishEvent; +use Extcode\CartGirosolution\EventListener\Order\Payment\ClearCart; +use Extcode\CartGirosolution\EventListener\Order\Payment\ProviderRedirect; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator; -return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $container) { +return static function (ContainerConfigurator $containerConfigurator, ContainerBuilder $container): void { $services = $containerConfigurator->services(); - $services - ->instanceof(CredentialLoaderInterface::class) - ->tag('cartGirosolution.credentialLoader'); $services ->defaults() ->autowire() - ->autoconfigure(); + ->autoconfigure() + ->private(); + + $services + ->instanceof(CredentialLoaderInterface::class) + ->tag('cartGirosolution.credentialLoader'); $services - ->load( - 'Extcode\\CartGirosolution\\Configuration\\', - '../Classes/Configuration/' - ); + ->load('Extcode\\CartGirosolution\\', '../Classes/*'); $services->set(CredentialLoaderRegistry::class) ->arg('$credentialLoaders', tagged_iterator('cartGirosolution.credentialLoader')); + + $services->set(ClearCart::class) + ->tag('event.listener', [ + 'identifier' => 'cart-girosolution--order--payment--clear-cart', + 'event' => PaymentEvent::class, + 'before' => 'cart-girosolution--order--payment--provider-redirect', + ]); + + $services->set(ProviderRedirect::class) + ->tag('event.listener', [ + 'identifier' => 'cart-girosolution--order--payment--provider-redirect', + 'event' => PaymentEvent::class, + ]); + + $services->set('cart-girosolution--event-listener--order--finish--email', Email::class) + ->tag('event.listener', [ + 'identifier' => 'cart-girosolution--order--finish--email', + 'event' => FinishEvent::class, + ]); }; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml deleted file mode 100644 index ff5a9ba..0000000 --- a/Configuration/Services.yaml +++ /dev/null @@ -1,30 +0,0 @@ -services: - _defaults: - autowire: true - autoconfigure: true - public: false - - Extcode\CartGirosolution\: - resource: '../Classes/*' - exclude: - - '../Classes/Configuration/*' - - Extcode\CartGirosolution\EventListener\Order\Payment\ClearCart: - tags: - - name: event.listener - identifier: 'cart-girosolution--order--payment--clear-cart' - event: Extcode\Cart\Event\Order\PaymentEvent - before: 'cart-girosolution--order--payment--provider-redirect' - - Extcode\CartGirosolution\EventListener\Order\Payment\ProviderRedirect: - tags: - - name: event.listener - identifier: 'cart-girosolution--order--payment--provider-redirect' - event: Extcode\Cart\Event\Order\PaymentEvent - - Extcode\CartGirosolution\EventListener\Order\Finish\Email: - class: 'Extcode\Cart\EventListener\Order\Finish\Email' - tags: - - name: event.listener - identifier: 'cart-girosolution--order--finish--email' - event: Extcode\CartGirosolution\Event\Order\FinishEvent diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index 8564cef..9b8c57c 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -1,5 +1,7 @@ `__ + +Description +=========== + +After a payment with Girosolution the extension dispatches its own +``Extcode\CartGirosolution\Event\Order\FinishEvent``. The email listener of +EXT:cart is registered for this event, so the mails to the buyer and the +seller are sent. + +The service of this listener had the id +``Extcode\CartGirosolution\EventListener\Order\Finish\Email``, which looked +like a class of this extension, but no such class exists. The service id was +renamed to ``cart-girosolution--event-listener--order--finish--email``. + +The identifier of the event listener +``cart-girosolution--order--finish--email`` is unchanged. + +Affected Installations +====================== + +Installations which reference the service by its id, e.g. to replace or to +remove the listener in their own service configuration. + +Migration +========= + +Use the new service id +``cart-girosolution--event-listener--order--finish--email``. Listeners which +use the identifier of the event listener in ``before`` or ``after`` do not +need to be changed. + +.. index:: Frontend diff --git a/Documentation/Changelog/6.0/Index.rst b/Documentation/Changelog/6.0/Index.rst index 0f79465..9e483da 100644 --- a/Documentation/Changelog/6.0/Index.rst +++ b/Documentation/Changelog/6.0/Index.rst @@ -4,4 +4,20 @@ 6.0 Changes =========== -The version 6.x is a release for extcode/cart 10.x. \ No newline at end of file +The version 6.x is a release for extcode/cart 11.x. + +**Table of contents** + +.. contents:: + :local: + :depth: 1 + +Breaking +-------- + +.. toctree:: + :maxdepth: 1 + :titlesonly: + :glob: + + Breaking-* diff --git a/Documentation/Changelog/7.0/Index.rst b/Documentation/Changelog/7.0/Index.rst new file mode 100644 index 0000000..172fed2 --- /dev/null +++ b/Documentation/Changelog/7.0/Index.rst @@ -0,0 +1,7 @@ +.. include:: ../../Includes.rst.txt + +=========== +7.0 Changes +=========== + +The version 7.x is a release for extcode/cart 12.x. diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index a95d7e4..0c51da9 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -7,6 +7,7 @@ ChangeLog :maxdepth: 3 :titlesonly: + 7.0/Index 6.0/Index 5.0/Index 4.0/Index diff --git a/Documentation/Introduction/Index.rst b/Documentation/Introduction/Index.rst index 3a53e2b..dbeb1ae 100644 --- a/Documentation/Introduction/Index.rst +++ b/Documentation/Introduction/Index.rst @@ -13,5 +13,6 @@ Cart Girosolution is a payment provider and implements the Girosolution Payment :maxdepth: 2 :titlesonly: + SupportedVersions/Index Support/Index Sponsoring/Index diff --git a/Documentation/Introduction/SupportedVersions/Index.rst b/Documentation/Introduction/SupportedVersions/Index.rst new file mode 100644 index 0000000..fbb535c --- /dev/null +++ b/Documentation/Introduction/SupportedVersions/Index.rst @@ -0,0 +1,32 @@ +.. include:: ../../Includes.rst.txt + +.. _supported-versions: + +================== +Supported versions +================== + +The table lists the compatibility of all versions with TYPO3 and PHP and which +versions are still supported. + +================= ========== ========= ==================================== +Cart Girosolution TYPO3 PHP Support/Development +================= ========== ========= ==================================== +7.x.x 14.3 8.2 - 8.5 Features, Bugfixes, Security Updates +6.x.x 13.4 8.2 - 8.5 Bugfixes, Security Updates +5.x.x 12.4 8.1+ Security Updates +4.x.x 10.4, 11.5 7.2+ +3.x.x 10.4 7.2 - 7.4 +2.x.x 9.5 7.2 - 7.4 +1.x.x 8.7 7.0 - 7.4 +================= ========== ========= ==================================== + +If you need extended support for features and bug fixes outside of the +currently supported versions, we are happy to offer paid services. + +Security +======== + +Security updates are only provided for supported versions. Please do not report +security issues in public GitHub issues or pull requests. Report them to the +TYPO3 Security Team via security@typo3.org instead. diff --git a/README.md b/README.md index e6a30ea..cee4914 100644 --- a/README.md +++ b/README.md @@ -3,52 +3,36 @@ Cart is a small but powerful extension which "solely" adds a shopping cart to your TYPO3 installation. Cart Girosolution is a payment provider. +Read the [extension documentation](https://docs.typo3.org/p/extcode/cart-girosolution/main/en-us/). + ## 1. Features - Redirects customer to Girosolution for payment. ## 2. Installation -#### Installation using Composer - -The recommended way to install the extension is by using [Composer][2]. In your Composer based TYPO3 project root, just do `composer require extcode/cart-girosolution`. - -#### Installation as extension from TYPO3 Extension Repository (TER) +Please have a look into the [installation chapter of the documentation](https://docs.typo3.org/p/extcode/cart-girosolution/main/en-us/Administrator/Installation/Index.html). -The extension can only be installed via composer. Installation via the TER is not possible. +## 3. Versions -## 3. Administration +### 3.1 Compatibility and supported versions -## 3.1 Compatibility and supported Versions - -| Cart Girosolution | TYPO3 | PHP | Support/Development | -|-------------------|------------|-----------|--------------------------------------| -| 6.x.x | 13.4 | 8.2+ | Features, Bugfixes, Security Updates | -| 5.x.x | 12.4 | 8.1+ | Bugfixes, Security Updates | -| 4.x.x | 10.4, 11.5 | 7.2+ | Security Updates | -| 3.x.x | 10.4 | 7.2 - 7.4 | | -| 2.x.x | 9.5 | 7.2 - 7.4 | | -| 1.x.x | 8.7 | 7.0 - 7.4 | | +The compatibility with TYPO3 and PHP and the support status of all versions are listed in the +[official extension documentation in chapter supported versions](https://docs.typo3.org/p/extcode/cart-girosolution/main/en-us/Introduction/SupportedVersions/Index.html). If you need extended support for features and bug fixes outside of the currently supported versions, we are happy to offer paid services. -### 3.2. Changelog - -Please have a look into the [official extension documentation in changelog chapter](https://docs.typo3.org/typo3cms/extensions/cart_girosolution/Misc/Changelog/Index.html) +### 3.2 Changelog -### 3.3. Release Management +Please have a look into the [official extension documentation in changelog chapter](https://docs.typo3.org/p/extcode/cart-girosolution/main/en-us/Changelog/Index.html) -News uses **semantic versioning** which basically means for you, that -- **bugfix updates** (e.g. 1.0.0 => 1.0.1) just includes small bugfixes or security relevant stuff without breaking changes. -- **minor updates** (e.g. 1.0.0 => 1.1.0) includes new features and smaller tasks without breaking changes. -- **major updates** (e.g. 1.0.0 => 2.0.0) breaking changes wich can be refactorings, features or bugfixes. +**Attention:** Before updating to a new minor version or upgrading to a new major version, be sure to check the +changelog section in the documentation. +Sometimes minor versions also result in minor adjustments to own templates or configurations. ## 4. Sponsoring * Ask for an invoice. * [GitHub Sponsors](https://github.com/sponsors/extcode) * [PayPal.Me](https://paypal.me/extcart) - -[1]: https://docs.typo3.org/p/extcode/cart-girosolution/main/en-us/ -[2]: https://getcomposer.org/ diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index 8306b28..87c3c3f 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -1,5 +1,5 @@ - +
diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..ed5c6b0 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,15 @@ +# Security Policy + +## Supported Versions + +Security updates are only provided for supported versions. The support status +of all versions is listed in the +[official extension documentation in chapter supported versions](https://docs.typo3.org/p/extcode/cart-girosolution/main/en-us/Introduction/SupportedVersions/Index.html). + +## Reporting a Vulnerability + +Please do not report security issues in public GitHub issues or pull requests. + +Report them to the TYPO3 Security Team via security@typo3.org. The team +coordinates the fix and the publication of a security advisory with the +maintainers. diff --git a/Tests/Functional/Configuration/EventListenerRegistrationTest.php b/Tests/Functional/Configuration/EventListenerRegistrationTest.php new file mode 100644 index 0000000..f552715 --- /dev/null +++ b/Tests/Functional/Configuration/EventListenerRegistrationTest.php @@ -0,0 +1,73 @@ +getListenerDefinitions(PaymentEvent::class), + array_flip([ + 'cart-girosolution--order--payment--clear-cart', + 'cart-girosolution--order--payment--provider-redirect', + ]) + ); + + self::assertSame( + [ + 'cart-girosolution--order--payment--clear-cart' => ClearCart::class, + 'cart-girosolution--order--payment--provider-redirect' => ProviderRedirect::class, + ], + array_map(static fn(array $listener): string => $listener['service'], $listeners) + ); + } + + #[Test] + public function sendsTheMailsOfCartAfterTheFinishedPayment(): void + { + $listeners = $this->getListenerDefinitions(FinishEvent::class); + + self::assertArrayHasKey('cart-girosolution--order--finish--email', $listeners); + self::assertSame( + 'cart-girosolution--event-listener--order--finish--email', + $listeners['cart-girosolution--order--finish--email']['service'] + ); + } + + /** + * @return array + */ + private function getListenerDefinitions(string $event): array + { + return $this->get(ListenerProvider::class)->getAllListenerDefinitions()[$event] ?? []; + } +} diff --git a/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php b/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php new file mode 100644 index 0000000..ffaa220 --- /dev/null +++ b/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php @@ -0,0 +1,174 @@ + 'typo3conf/sites', + ]; + + protected array $configurationToUseInTestInstance = [ + 'FE' => [ + 'cacheHash' => [ + 'enforceValidation' => false, + ], + ], + 'MAIL' => [ + 'transport' => 'null', + ], + ]; + + protected function setUp(): void + { + parent::setUp(); + + $this->importPHPDataSet(__DIR__ . '/../../Fixtures/DataSets/Base.php'); + $this->importPHPDataSet(__DIR__ . '/../../Fixtures/DataSets/Order.php'); + + $cart = new Cart([]); + $cart->setBillingCountry('de'); + $cart->setOrderNumber('ORD-2026-0001'); + + $this->get(ConnectionPool::class) + ->getConnectionForTable('tx_cart_domain_model_cart') + ->insert('tx_cart_domain_model_cart', [ + 'uid' => 1, + 'pid' => 2, + 's_hash' => self::CART_HASH, + 'order_item' => 1, + 'serialized_cart' => serialize($cart), + ]); + + EventRecorder::reset(); + } + + /** + * Sends the notification, Girosolution calls the notify URL in the + * background after the payment. + */ + protected function sendNotification( + string $resultPayment, + string $secret, + ?string $cartHash = self::CART_HASH, + ): ResponseInterface { + return $this->callPaymentController('notify', $resultPayment, $secret, $cartHash); + } + + /** + * Sends the redirect, Girosolution redirects the customer to the redirect + * URL after the payment. + */ + protected function sendRedirect( + string $resultPayment, + string $secret, + ?string $cartHash = self::CART_HASH, + ): ResponseInterface { + return $this->callPaymentController('redirect', $resultPayment, $secret, $cartHash); + } + + /** + * @param string|null $cartHash null omits the hash argument + */ + private function callPaymentController( + string $action, + string $resultPayment, + string $secret, + ?string $cartHash, + ): ResponseInterface { + $notification = [ + 'gcReference' => self::GC_REFERENCE, + 'gcMerchantTxId' => md5('ORD-2026-0001'), + 'gcBackendTxId' => 'gc-backend-tx-0001', + 'gcAmount' => '11900', + 'gcCurrency' => 'EUR', + 'gcResultPayment' => $resultPayment, + ]; + $notification['gcHash'] = hash_hmac('md5', implode('', $notification), $secret); + + // The controller reads the notification from $_GET, like the SDK of Girosolution expects it. + $_GET = $notification; + + $pluginArguments = [ + 'tx_cartgirosolution_cart[controller]' => 'Order\\Payment', + 'tx_cartgirosolution_cart[action]' => $action, + ]; + if ($cartHash !== null) { + $pluginArguments['tx_cartgirosolution_cart[hash]'] = $cartHash; + } + + return $this->executeFrontendSubRequest( + (new InternalRequest('http://localhost/')) + ->withPageId(1) + ->withQueryParameters(['type' => 2278106] + $pluginArguments + $notification) + ); + } + + protected function setPaymentProvider(string $provider): void + { + $this->get(ConnectionPool::class) + ->getConnectionForTable('tx_cart_domain_model_order_payment') + ->update('tx_cart_domain_model_order_payment', ['provider' => $provider], ['uid' => 1]); + } + + protected function getPayment(): array + { + return $this->getRecord('tx_cart_domain_model_order_payment', ['status']); + } + + protected function getTransaction(): array + { + return $this->getRecord('tx_cart_domain_model_order_transaction', ['status', 'external_status_code', 'note']); + } + + private function getRecord(string $table, array $fields): array + { + $record = $this->get(ConnectionPool::class) + ->getConnectionForTable($table) + ->select($fields, $table, ['uid' => 1]) + ->fetchAssociative(); + + self::assertIsArray($record); + + return $record; + } +} diff --git a/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php b/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php new file mode 100644 index 0000000..fcc7ee9 --- /dev/null +++ b/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php @@ -0,0 +1,202 @@ +sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertSame('paid', $this->getPayment()['status']); + self::assertSame( + [ + 'status' => 'paid', + 'external_status_code' => self::RESULT_PAYMENT_SUCCESSFUL, + 'note' => 'gc-backend-tx-0001', + ], + $this->getTransaction() + ); + } + + #[Test] + public function successfulPaymentDispatchesFinishEvent(): void + { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertCount(1, EventRecorder::getEvents()[FinishEvent::class] ?? []); + self::assertArrayNotHasKey(CancelEvent::class, EventRecorder::getEvents()); + + $event = EventRecorder::getEvents()[FinishEvent::class][0]; + self::assertInstanceOf(FinishEvent::class, $event); + self::assertSame('ORD-2026-0001', $event->getOrderItem()->getOrderNumber()); + self::assertSame('1', (string)$event->getSettings()['settings']['cart']['pid']); + } + + #[Test] + public function canceledPaymentMarksPaymentAndTransactionAsCanceled(): void + { + $this->sendNotification(self::RESULT_PAYMENT_CANCELED, self::TYPOSCRIPT_SECRET); + + self::assertSame('canceled', $this->getPayment()['status']); + self::assertSame( + [ + 'status' => 'canceled', + 'external_status_code' => self::RESULT_PAYMENT_CANCELED, + 'note' => 'gc-backend-tx-0001', + ], + $this->getTransaction() + ); + } + + #[Test] + public function canceledPaymentDispatchesCancelEvent(): void + { + $this->sendNotification(self::RESULT_PAYMENT_CANCELED, self::TYPOSCRIPT_SECRET); + + self::assertCount(1, EventRecorder::getEvents()[CancelEvent::class] ?? []); + self::assertArrayNotHasKey(FinishEvent::class, EventRecorder::getEvents()); + } + + #[Test] + public function repeatedNotificationDoesNotDispatchTheEventAgain(): void + { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertSame('paid', $this->getPayment()['status']); + self::assertCount(1, EventRecorder::getEvents()[FinishEvent::class] ?? []); + } + + #[Test] + public function notificationWithWrongHashIsRejected(): void + { + try { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, 'wrong-secret'); + self::fail('The notification with a wrong hash has been accepted.'); + } catch (GiroCheckout_SDK_Exception_helper $exception) { + self::assertStringContainsString('hash mismatch', $exception->getMessage()); + } + + self::assertSame('open', $this->getPayment()['status']); + self::assertSame('created', $this->getTransaction()['status']); + self::assertSame([], EventRecorder::getEvents()); + } + + #[Test] + public function notificationForUnknownCartIsRejected(): void + { + try { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET, 'unknown-cart-hash'); + self::fail('The notification for an unknown cart has been accepted.'); + } catch (\InvalidArgumentException $exception) { + self::assertSame(1734097682, $exception->getCode()); + } + + self::assertSame('open', $this->getPayment()['status']); + self::assertSame([], EventRecorder::getEvents()); + } + + #[Test] + public function notificationWithoutCartHashIsRejected(): void + { + try { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET, null); + self::fail('The notification without cart hash has been accepted.'); + } catch (\InvalidArgumentException $exception) { + self::assertSame(1734098478, $exception->getCode()); + } + + self::assertSame('open', $this->getPayment()['status']); + } + + #[Test] + public function paypalPaymentIsVerifiedWithPaypalCredentials(): void + { + $this->setPaymentProvider('GIROSOLUTION_PAYPAL'); + + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, 'paypal-secret'); + + self::assertSame('paid', $this->getPayment()['status']); + self::assertCount(1, EventRecorder::getEvents()[FinishEvent::class] ?? []); + } + + #[Test] + public function paypalPaymentIsNotVerifiedWithCreditCardCredentials(): void + { + $this->setPaymentProvider('GIROSOLUTION_PAYPAL'); + + $this->expectException(GiroCheckout_SDK_Exception_helper::class); + + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + } + + #[Test] + public function notificationForUnknownClearingTypeIsRejected(): void + { + $this->setPaymentProvider('GIROSOLUTION_UNKNOWN'); + + try { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + self::fail('The notification for an unknown clearing type has been accepted.'); + } catch (\InvalidArgumentException $exception) { + self::assertSame(1734099627, $exception->getCode()); + } + + self::assertSame('open', $this->getPayment()['status']); + } + + #[Test] + public function notificationForPaymentWithoutTransactionIsRejected(): void + { + $this->get(ConnectionPool::class) + ->getConnectionForTable('tx_cart_domain_model_order_transaction') + ->delete('tx_cart_domain_model_order_transaction', ['uid' => 1]); + $this->get(ConnectionPool::class) + ->getConnectionForTable('tx_cart_domain_model_order_payment') + ->update('tx_cart_domain_model_order_payment', ['transactions' => 0], ['uid' => 1]); + + try { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + self::fail('The notification for a payment without transaction has been accepted.'); + } catch (\Exception $exception) { + self::assertSame(1731616906, $exception->getCode()); + } + + self::assertSame('open', $this->getPayment()['status']); + self::assertSame([], EventRecorder::getEvents()); + } + + #[Test] + public function notifyActionRespondsWithEmptyBody(): void + { + $response = $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertSame(200, $response->getStatusCode()); + self::assertSame('', trim((string)$response->getBody())); + } +} diff --git a/Tests/Functional/Controller/Order/PaymentControllerRedirectActionTest.php b/Tests/Functional/Controller/Order/PaymentControllerRedirectActionTest.php new file mode 100644 index 0000000..5002198 --- /dev/null +++ b/Tests/Functional/Controller/Order/PaymentControllerRedirectActionTest.php @@ -0,0 +1,226 @@ +sendRedirect(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertSame(303, $response->getStatusCode()); + self::assertSame( + [ + 'action' => 'show', + 'controller' => 'Cart\\Order', + 'orderItem' => '1', + ], + $this->getCartPluginArgumentsOfRedirect($response) + ); + } + + #[Test] + public function successfulPaymentMarksPaymentAndTransactionAsPaid(): void + { + $this->sendRedirect(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertSame('paid', $this->getPayment()['status']); + self::assertSame( + [ + 'status' => 'paid', + 'external_status_code' => self::RESULT_PAYMENT_SUCCESSFUL, + 'note' => 'gc-backend-tx-0001', + ], + $this->getTransaction() + ); + } + + #[Test] + public function successfulPaymentDispatchesFinishEvent(): void + { + $this->sendRedirect(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertCount(1, EventRecorder::getEvents()[FinishEvent::class] ?? []); + self::assertArrayNotHasKey(CancelEvent::class, EventRecorder::getEvents()); + } + + #[Test] + public function successfulPaymentDoesNotRestoreTheCart(): void + { + $this->sendRedirect(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertSame([], $this->getSessionData()); + } + + /** + * Girosolution usually sends the notification before the customer is + * redirected. The event must not be dispatched a second time. + */ + #[Test] + public function redirectAfterNotificationDoesNotDispatchTheEventAgain(): void + { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + $response = $this->sendRedirect(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + + self::assertSame(303, $response->getStatusCode()); + self::assertSame('paid', $this->getPayment()['status']); + self::assertCount(1, EventRecorder::getEvents()[FinishEvent::class] ?? []); + } + + #[Test] + public function canceledPaymentRedirectsToTheCart(): void + { + $response = $this->sendRedirect(self::RESULT_PAYMENT_CANCELED, self::TYPOSCRIPT_SECRET); + + self::assertSame(303, $response->getStatusCode()); + self::assertSame( + [ + 'action' => 'show', + 'controller' => 'Cart\\Cart', + ], + $this->getCartPluginArgumentsOfRedirect($response) + ); + } + + #[Test] + public function canceledPaymentMarksPaymentAndTransactionAsCanceled(): void + { + $this->sendRedirect(self::RESULT_PAYMENT_CANCELED, self::TYPOSCRIPT_SECRET); + + self::assertSame('canceled', $this->getPayment()['status']); + self::assertSame( + [ + 'status' => 'canceled', + 'external_status_code' => self::RESULT_PAYMENT_CANCELED, + 'note' => 'gc-backend-tx-0001', + ], + $this->getTransaction() + ); + } + + #[Test] + public function canceledPaymentDispatchesCancelEvent(): void + { + $this->sendRedirect(self::RESULT_PAYMENT_CANCELED, self::TYPOSCRIPT_SECRET); + + self::assertCount(1, EventRecorder::getEvents()[CancelEvent::class] ?? []); + self::assertArrayNotHasKey(FinishEvent::class, EventRecorder::getEvents()); + } + + #[Test] + public function canceledPaymentRestoresTheCartInTheSession(): void + { + $this->sendRedirect(self::RESULT_PAYMENT_CANCELED, self::TYPOSCRIPT_SECRET); + + $sessionData = $this->getSessionData(); + self::assertArrayHasKey('cart_1', $sessionData); + + $cart = unserialize($sessionData['cart_1']); + self::assertInstanceOf(Cart::class, $cart); + self::assertSame('de', $cart->getBillingCountry()); + self::assertSame('', $cart->getOrderNumber()); + } + + #[Test] + public function canceledPaymentAddsFlashMessageForTheCart(): void + { + $this->sendRedirect(self::RESULT_PAYMENT_CANCELED, self::TYPOSCRIPT_SECRET); + + $sessionData = $this->getSessionData(); + self::assertArrayHasKey('extbase.flashmessages.tx_cart_cart', $sessionData); + self::assertStringContainsString( + 'The payment process was aborted.', + json_encode($sessionData['extbase.flashmessages.tx_cart_cart'], JSON_THROW_ON_ERROR) + ); + } + + #[Test] + public function redirectWithWrongHashIsRejected(): void + { + try { + $this->sendRedirect(self::RESULT_PAYMENT_SUCCESSFUL, 'wrong-secret'); + self::fail('The redirect with a wrong hash has been accepted.'); + } catch (GiroCheckout_SDK_Exception_helper $exception) { + self::assertStringContainsString('hash mismatch', $exception->getMessage()); + } + + self::assertSame('open', $this->getPayment()['status']); + self::assertSame([], EventRecorder::getEvents()); + self::assertSame([], $this->getSessionData()); + } + + #[Test] + public function redirectWithoutCartHashIsRejected(): void + { + try { + $this->sendRedirect(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET, null); + self::fail('The redirect without cart hash has been accepted.'); + } catch (\InvalidArgumentException $exception) { + self::assertSame(1734098478, $exception->getCode()); + } + + self::assertSame('open', $this->getPayment()['status']); + } + + /** + * @return array + */ + private function getCartPluginArgumentsOfRedirect(ResponseInterface $response): array + { + parse_str((string)parse_url($response->getHeaderLine('location'), PHP_URL_QUERY), $query); + + self::assertIsArray($query['tx_cart_cart'] ?? null); + + return $query['tx_cart_cart']; + } + + /** + * Returns the session data of the frontend user, the test sends one + * request, so there is at most one session. + */ + private function getSessionData(): array + { + $sessions = $this->get(ConnectionPool::class) + ->getConnectionForTable('fe_sessions') + ->select(['ses_data'], 'fe_sessions') + ->fetchAllAssociative(); + + self::assertLessThanOrEqual(1, count($sessions)); + + if ($sessions === []) { + return []; + } + + $sessionData = unserialize($sessions[0]['ses_data'], ['allowed_classes' => false]); + self::assertIsArray($sessionData); + + return $sessionData; + } +} diff --git a/Tests/Functional/Controller/Order/PaymentControllerWithCredentialsFromConfVarsTest.php b/Tests/Functional/Controller/Order/PaymentControllerWithCredentialsFromConfVarsTest.php new file mode 100644 index 0000000..eb09264 --- /dev/null +++ b/Tests/Functional/Controller/Order/PaymentControllerWithCredentialsFromConfVarsTest.php @@ -0,0 +1,61 @@ +configurationToUseInTestInstance['EXTENSIONS']['cart_girosolution'] = [ + 'credentials' => [ + 'creditCard' => [ + 'password' => self::CONF_VARS_SECRET, + ], + ], + ]; + + parent::setUp(); + } + + #[Test] + public function acceptsNotificationSignedWithPasswordOfConfVars(): void + { + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::CONF_VARS_SECRET); + + self::assertSame('paid', $this->getPayment()['status']); + } + + #[Test] + public function rejectsNotificationSignedWithPasswordOfTypoScript(): void + { + $this->expectException(GiroCheckout_SDK_Exception_helper::class); + + $this->sendNotification(self::RESULT_PAYMENT_SUCCESSFUL, self::TYPOSCRIPT_SECRET); + } +} diff --git a/Tests/Functional/Fixtures/DataSets/Base.php b/Tests/Functional/Fixtures/DataSets/Base.php new file mode 100644 index 0000000..8526419 --- /dev/null +++ b/Tests/Functional/Fixtures/DataSets/Base.php @@ -0,0 +1,54 @@ + [ + [ + 'uid' => 1, + 'pid' => 0, + 'title' => 'Cart', + 'doktype' => PageRepository::DOKTYPE_DEFAULT, + 'slug' => '/', + 'is_siteroot' => 1, + ], + [ + 'uid' => 2, + 'pid' => 1, + 'title' => 'Orders', + 'doktype' => PageRepository::DOKTYPE_SYSFOLDER, + 'slug' => '/orders', + ], + ], + 'sys_template' => [ + [ + 'uid' => 1, + 'pid' => 1, + 'title' => 'Root', + 'root' => 1, + 'clear' => 3, + 'include_static_file' => implode(',', [ + 'EXT:cart/Configuration/TypoScript', + 'EXT:cart_girosolution/Configuration/TypoScript', + ]), + 'constants' => implode(PHP_EOL, [ + 'plugin.tx_cart.settings.cart.pid = 1', + 'plugin.tx_cart.settings.order.pid = 2', + ]), + 'config' => implode(PHP_EOL, [ + 'plugin.tx_cartgirosolution.credentials.creditCard {', + ' merchantId = 1234', + ' projectId = 5678', + ' password = credit-card-secret', + '}', + 'plugin.tx_cartgirosolution.credentials.paypal {', + ' merchantId = 1234', + ' projectId = 9012', + ' password = paypal-secret', + '}', + ]), + ], + ], +]; diff --git a/Tests/Functional/Fixtures/DataSets/Order.php b/Tests/Functional/Fixtures/DataSets/Order.php new file mode 100644 index 0000000..6089abc --- /dev/null +++ b/Tests/Functional/Fixtures/DataSets/Order.php @@ -0,0 +1,37 @@ + [ + [ + 'uid' => 1, + 'pid' => 2, + 'order_number' => 'ORD-2026-0001', + 'currency_code' => 'EUR', + 'total_gross' => 119.0, + 'payment' => 1, + ], + ], + 'tx_cart_domain_model_order_payment' => [ + [ + 'uid' => 1, + 'pid' => 2, + 'item' => 1, + 'service_id' => 1, + 'name' => 'Credit Card', + 'provider' => 'GIROSOLUTION_CREDITCARD', + 'status' => 'open', + 'transactions' => 1, + ], + ], + 'tx_cart_domain_model_order_transaction' => [ + [ + 'uid' => 1, + 'pid' => 2, + 'payment' => 1, + 'txn_id' => 'gc-reference-0001', + 'status' => 'created', + ], + ], +]; diff --git a/Tests/Functional/Fixtures/Extensions/girosolution_test/Classes/EventListener/EventRecorder.php b/Tests/Functional/Fixtures/Extensions/girosolution_test/Classes/EventListener/EventRecorder.php new file mode 100644 index 0000000..86ec141 --- /dev/null +++ b/Tests/Functional/Fixtures/Extensions/girosolution_test/Classes/EventListener/EventRecorder.php @@ -0,0 +1,45 @@ + + */ + private static array $events = []; + + public function __invoke(object $event): void + { + self::$events[$event::class][] = $event; + } + + /** + * @return array + */ + public static function getEvents(): array + { + return self::$events; + } + + public static function reset(): void + { + self::$events = []; + } +} diff --git a/Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.php b/Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.php new file mode 100644 index 0000000..acf5c45 --- /dev/null +++ b/Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.php @@ -0,0 +1,28 @@ +services(); + + $services + ->defaults() + ->autowire() + ->autoconfigure() + ->private(); + + $services->set(EventRecorder::class) + ->tag('event.listener', [ + 'identifier' => 'girosolution-test--order--finish--event-recorder', + 'event' => FinishEvent::class, + ]) + ->tag('event.listener', [ + 'identifier' => 'girosolution-test--order--cancel--event-recorder', + 'event' => CancelEvent::class, + ]); +}; diff --git a/Tests/Functional/Fixtures/Extensions/girosolution_test/composer.json b/Tests/Functional/Fixtures/Extensions/girosolution_test/composer.json new file mode 100644 index 0000000..84533a5 --- /dev/null +++ b/Tests/Functional/Fixtures/Extensions/girosolution_test/composer.json @@ -0,0 +1,21 @@ +{ + "name": "extcode/girosolution-test", + "type": "typo3-cms-extension", + "description": "Records the events of cart_girosolution in functional tests", + "license": [ + "GPL-2.0-or-later" + ], + "autoload": { + "psr-4": { + "Extcode\\GirosolutionTest\\": "Classes/" + } + }, + "require": { + "extcode/cart-girosolution": "*" + }, + "extra": { + "typo3/cms": { + "extension-key": "girosolution_test" + } + } +} diff --git a/Tests/Functional/Fixtures/Sites/default/config.yaml b/Tests/Functional/Fixtures/Sites/default/config.yaml new file mode 100644 index 0000000..be8cc08 --- /dev/null +++ b/Tests/Functional/Fixtures/Sites/default/config.yaml @@ -0,0 +1,13 @@ +base: 'http://localhost/' +languages: + - + title: English + enabled: true + base: / + typo3Language: default + locale: en_US.UTF-8 + navigationTitle: English + flag: us + languageId: 0 +rootPageId: 1 +websiteTitle: tests diff --git a/Tests/Unit/Configuration/CredentialLoaderRegistryTest.php b/Tests/Unit/Configuration/CredentialLoaderRegistryTest.php new file mode 100644 index 0000000..c907c51 --- /dev/null +++ b/Tests/Unit/Configuration/CredentialLoaderRegistryTest.php @@ -0,0 +1,129 @@ +getCredentials()); + } + + #[Test] + public function returnsCredentialsOfASingleLoader(): void + { + $credentials = [ + 'creditCard' => [ + 'merchantId' => '1234', + 'projectId' => '5678', + 'password' => 'secret', + ], + ]; + + $subject = new CredentialLoaderRegistry([ + $this->createLoader($credentials), + ]); + + self::assertSame($credentials, $subject->getCredentials()); + } + + #[Test] + public function ignoresLoadersWithoutCredentials(): void + { + $credentials = [ + 'paypal' => [ + 'password' => 'secret', + ], + ]; + + $subject = new CredentialLoaderRegistry([ + $this->createLoader([]), + $this->createLoader($credentials), + $this->createLoader([]), + ]); + + self::assertSame($credentials, $subject->getCredentials()); + } + + /** + * The loaders are passed ordered by priority, the loader with the highest + * priority comes first. Its values win, the following loaders only add + * values which are missing so far. + */ + #[Test] + public function valuesOfEarlierLoadersOverrideValuesOfLaterLoaders(): void + { + $subject = new CredentialLoaderRegistry([ + $this->createLoader([ + 'creditCard' => [ + 'password' => 'secret-from-first-loader', + ], + ]), + $this->createLoader([ + 'creditCard' => [ + 'merchantId' => '1234', + 'password' => 'secret-from-second-loader', + ], + 'giropay' => [ + 'password' => 'giropay-secret', + ], + ]), + ]); + + self::assertSame( + [ + 'creditCard' => [ + 'merchantId' => '1234', + 'password' => 'secret-from-first-loader', + ], + 'giropay' => [ + 'password' => 'giropay-secret', + ], + ], + $subject->getCredentials() + ); + } + + #[Test] + public function acceptsTraversableOfLoaders(): void + { + $credentials = [ + 'paydirekt' => [ + 'password' => 'secret', + ], + ]; + + $subject = new CredentialLoaderRegistry( + new \ArrayIterator([$this->createLoader($credentials)]) + ); + + self::assertSame($credentials, $subject->getCredentials()); + } + + private function createLoader(array $credentials): CredentialLoaderInterface + { + $loader = self::createStub(CredentialLoaderInterface::class); + $loader->method('getCredentials')->willReturn($credentials); + + return $loader; + } +} diff --git a/Tests/Unit/Configuration/CredentialsFromConfVarsTest.php b/Tests/Unit/Configuration/CredentialsFromConfVarsTest.php new file mode 100644 index 0000000..74e702d --- /dev/null +++ b/Tests/Unit/Configuration/CredentialsFromConfVarsTest.php @@ -0,0 +1,100 @@ +createMock(ExtensionConfiguration::class); + $extensionConfiguration + ->expects(self::once()) + ->method('get') + ->with('cart_girosolution') + ->willReturn([]); + + new CredentialsFromConfVars($extensionConfiguration); + } + + #[Test] + public function returnsCredentialsOfTheExtensionConfiguration(): void + { + $credentials = [ + 'creditCard' => [ + 'merchantId' => '1234', + 'projectId' => '5678', + 'password' => 'secret', + ], + ]; + + $subject = new CredentialsFromConfVars( + $this->createExtensionConfiguration(['credentials' => $credentials]) + ); + + self::assertSame($credentials, $subject->getCredentials()); + } + + public static function configurationWithoutCredentialsDataProvider(): \Generator + { + yield 'empty configuration' => [[]]; + yield 'configuration without credentials' => [['someOtherSetting' => '1']]; + yield 'credentials as string' => [['credentials' => 'secret']]; + } + + #[Test] + #[DataProvider('configurationWithoutCredentialsDataProvider')] + public function returnsEmptyCredentialsWithoutCredentialsInConfiguration(array $configuration): void + { + $subject = new CredentialsFromConfVars( + $this->createExtensionConfiguration($configuration) + ); + + self::assertSame([], $subject->getCredentials()); + } + + #[Test] + public function returnsEmptyCredentialsIfTheExtensionIsNotConfigured(): void + { + $extensionConfiguration = self::createStub(ExtensionConfiguration::class); + $extensionConfiguration + ->method('get') + ->willThrowException(new ExtensionConfigurationExtensionNotConfiguredException('not configured', 1509654728)); + + $subject = new CredentialsFromConfVars($extensionConfiguration); + + self::assertSame([], $subject->getCredentials()); + } + + private function createExtensionConfiguration(array $configuration): ExtensionConfiguration + { + $extensionConfiguration = self::createStub(ExtensionConfiguration::class); + $extensionConfiguration->method('get')->willReturn($configuration); + + return $extensionConfiguration; + } +} diff --git a/Tests/Unit/Configuration/CredentialsFromTypoScriptTest.php b/Tests/Unit/Configuration/CredentialsFromTypoScriptTest.php new file mode 100644 index 0000000..14ee862 --- /dev/null +++ b/Tests/Unit/Configuration/CredentialsFromTypoScriptTest.php @@ -0,0 +1,90 @@ +createMock(ConfigurationManager::class); + $configurationManager + ->expects(self::once()) + ->method('getConfiguration') + ->with(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'CartGirosolution') + ->willReturn([]); + + new CredentialsFromTypoScript($configurationManager); + } + + #[Test] + public function returnsCredentialsOfTheTypoScript(): void + { + $credentials = [ + 'giropay' => [ + 'merchantId' => '1234', + 'projectId' => '5678', + 'password' => 'secret', + ], + ]; + + $subject = new CredentialsFromTypoScript( + $this->createConfigurationManager([ + 'redirectTypeNum' => '2278106', + 'credentials' => $credentials, + ]) + ); + + self::assertSame($credentials, $subject->getCredentials()); + } + + public static function configurationWithoutCredentialsDataProvider(): \Generator + { + yield 'empty configuration' => [[]]; + yield 'configuration without credentials' => [['redirectTypeNum' => '2278106']]; + yield 'credentials as string' => [['credentials' => 'secret']]; + } + + #[Test] + #[DataProvider('configurationWithoutCredentialsDataProvider')] + public function returnsEmptyCredentialsWithoutCredentialsInTypoScript(array $configuration): void + { + $subject = new CredentialsFromTypoScript( + $this->createConfigurationManager($configuration) + ); + + self::assertSame([], $subject->getCredentials()); + } + + private function createConfigurationManager(array $configuration): ConfigurationManager + { + $configurationManager = self::createStub(ConfigurationManager::class); + $configurationManager->method('getConfiguration')->willReturn($configuration); + + return $configurationManager; + } +} diff --git a/Tests/Unit/Event/Order/CancelEventTest.php b/Tests/Unit/Event/Order/CancelEventTest.php new file mode 100644 index 0000000..fa47103 --- /dev/null +++ b/Tests/Unit/Event/Order/CancelEventTest.php @@ -0,0 +1,92 @@ +cart = self::createStub(Cart::class); + $this->orderItem = new OrderItem(); + } + + #[Test] + public function implementsTheOrderEventInterfaces(): void + { + $subject = new CancelEvent($this->cart, $this->orderItem); + + self::assertInstanceOf(EventInterface::class, $subject); + self::assertInstanceOf(StoppableEventInterface::class, $subject); + } + + #[Test] + public function returnsGivenCartOrderItemAndSettings(): void + { + $settings = [ + 'settings' => [ + 'cart' => [ + 'pid' => '3', + ], + ], + ]; + + $subject = new CancelEvent($this->cart, $this->orderItem, $settings); + + self::assertSame($this->cart, $subject->getCart()); + self::assertSame($this->orderItem, $subject->getOrderItem()); + self::assertSame($settings, $subject->getSettings()); + } + + #[Test] + public function settingsAreEmptyByDefault(): void + { + $subject = new CancelEvent($this->cart, $this->orderItem); + + self::assertSame([], $subject->getSettings()); + } + + #[Test] + public function propagationIsNotStoppedByDefault(): void + { + $subject = new CancelEvent($this->cart, $this->orderItem); + + self::assertFalse($subject->isPropagationStopped()); + } + + #[Test] + public function propagationCanBeStoppedAndResumed(): void + { + $subject = new CancelEvent($this->cart, $this->orderItem); + + $subject->setPropagationStopped(true); + self::assertTrue($subject->isPropagationStopped()); + + $subject->setPropagationStopped(false); + self::assertFalse($subject->isPropagationStopped()); + } +} diff --git a/Tests/Unit/Event/Order/FinishEventTest.php b/Tests/Unit/Event/Order/FinishEventTest.php new file mode 100644 index 0000000..b1fb4e7 --- /dev/null +++ b/Tests/Unit/Event/Order/FinishEventTest.php @@ -0,0 +1,92 @@ +cart = self::createStub(Cart::class); + $this->orderItem = new OrderItem(); + } + + #[Test] + public function implementsTheOrderEventInterfaces(): void + { + $subject = new FinishEvent($this->cart, $this->orderItem); + + self::assertInstanceOf(EventInterface::class, $subject); + self::assertInstanceOf(StoppableEventInterface::class, $subject); + } + + #[Test] + public function returnsGivenCartOrderItemAndSettings(): void + { + $settings = [ + 'settings' => [ + 'cart' => [ + 'pid' => '3', + ], + ], + ]; + + $subject = new FinishEvent($this->cart, $this->orderItem, $settings); + + self::assertSame($this->cart, $subject->getCart()); + self::assertSame($this->orderItem, $subject->getOrderItem()); + self::assertSame($settings, $subject->getSettings()); + } + + #[Test] + public function settingsAreEmptyByDefault(): void + { + $subject = new FinishEvent($this->cart, $this->orderItem); + + self::assertSame([], $subject->getSettings()); + } + + #[Test] + public function propagationIsNotStoppedByDefault(): void + { + $subject = new FinishEvent($this->cart, $this->orderItem); + + self::assertFalse($subject->isPropagationStopped()); + } + + #[Test] + public function propagationCanBeStoppedAndResumed(): void + { + $subject = new FinishEvent($this->cart, $this->orderItem); + + $subject->setPropagationStopped(true); + self::assertTrue($subject->isPropagationStopped()); + + $subject->setPropagationStopped(false); + self::assertFalse($subject->isPropagationStopped()); + } +} diff --git a/Tests/Unit/EventListener/Order/Payment/ClearCartTest.php b/Tests/Unit/EventListener/Order/Payment/ClearCartTest.php new file mode 100644 index 0000000..213bad5 --- /dev/null +++ b/Tests/Unit/EventListener/Order/Payment/ClearCartTest.php @@ -0,0 +1,202 @@ + [ + 'cart' => [ + 'pid' => '3', + ], + ], + ]; + + private CartUtility&MockObject $cartUtility; + + private PaymentMethodsLoaderInterface&MockObject $paymentMethodsLoader; + + private SessionHandler&MockObject $sessionHandler; + + private Cart $cart; + + private ClearCart $subject; + + protected function setUp(): void + { + parent::setUp(); + + $this->cartUtility = $this->createMock(CartUtility::class); + $this->paymentMethodsLoader = $this->createMock(PaymentMethodsLoaderInterface::class); + $this->sessionHandler = $this->createMock(SessionHandler::class); + + $payment = self::createStub(ServiceInterface::class); + $payment->method('getId')->willReturn(self::PAYMENT_ID); + + $this->cart = self::createStub(Cart::class); + $this->cart->method('getPayment')->willReturn($payment); + + $this->subject = new ClearCart( + $this->cartUtility, + $this->paymentMethodsLoader, + $this->sessionHandler, + ); + } + + public static function otherProviderDataProvider(): \Generator + { + yield 'no provider' => ['']; + yield 'provider of another extension' => ['PAYPAL']; + yield 'provider of another extension with clearing type' => ['PAYONE_CREDITCARD']; + } + + #[Test] + #[DataProvider('otherProviderDataProvider')] + public function doesNothingForPaymentsOfOtherProviders(string $provider): void + { + $this->paymentMethodsLoader->expects(self::never())->method('getPaymentMethods'); + $this->cartUtility->expects(self::never())->method('getNewCart'); + $this->sessionHandler->expects(self::never())->method('writeCart'); + $this->sessionHandler->expects(self::never())->method('writeAddress'); + + ($this->subject)($this->createEvent($provider)); + } + + #[Test] + public function doesNotClearTheCartIfPreventClearCartIsSet(): void + { + $this->paymentMethodsLoader + ->method('getPaymentMethods') + ->willReturn($this->createPaymentMethods([ + self::PAYMENT_ID => [ + 'preventClearCart' => '1', + ], + ])); + + $this->cartUtility->expects(self::never())->method('getNewCart'); + $this->sessionHandler->expects(self::never())->method('writeCart'); + $this->sessionHandler->expects(self::never())->method('writeAddress'); + + ($this->subject)($this->createEvent('GIROSOLUTION_CREDITCARD')); + } + + public static function paymentMethodsWithoutPreventClearCartDataProvider(): \Generator + { + yield 'no payment methods' => [[]]; + yield 'preventClearCart not set' => [[self::PAYMENT_ID => []]]; + yield 'preventClearCart disabled' => [[self::PAYMENT_ID => ['preventClearCart' => '0']]]; + yield 'preventClearCart set for another payment' => [[self::PAYMENT_ID + 1 => ['preventClearCart' => '1']]]; + } + + /** + * @param array $paymentMethodConfigurations + */ + #[Test] + #[DataProvider('paymentMethodsWithoutPreventClearCartDataProvider')] + public function clearsCartAndAddressesForGirosolutionPayments(array $paymentMethodConfigurations): void + { + $this->paymentMethodsLoader + ->expects(self::once()) + ->method('getPaymentMethods') + ->with($this->cart) + ->willReturn($this->createPaymentMethods($paymentMethodConfigurations)); + + $newCart = self::createStub(Cart::class); + $this->cartUtility + ->expects(self::once()) + ->method('getNewCart') + ->with(self::SETTINGS) + ->willReturn($newCart); + + $this->sessionHandler + ->expects(self::once()) + ->method('writeCart') + ->with('3', $newCart); + + $writtenAddresses = []; + $this->sessionHandler + ->expects(self::exactly(2)) + ->method('writeAddress') + ->willReturnCallback(function (string $key, object $address) use (&$writtenAddresses): void { + $writtenAddresses[$key] = $address::class; + }); + + ($this->subject)($this->createEvent('GIROSOLUTION_GIROPAY')); + + self::assertSame( + [ + 'billing_address_3' => BillingAddress::class, + 'shipping_address_3' => ShippingAddress::class, + ], + $writtenAddresses + ); + } + + #[Test] + public function doesNotStopThePropagationOfTheEvent(): void + { + $event = $this->createEvent('GIROSOLUTION_PAYPAL'); + + ($this->subject)($event); + + self::assertFalse($event->isPropagationStopped()); + } + + /** + * Creates the payment methods like PaymentMethodsLoaderInterface returns + * them: services indexed by their id. + * + * @param array $configurations + * @return array + */ + private function createPaymentMethods(array $configurations): array + { + $paymentMethods = []; + foreach ($configurations as $id => $configuration) { + $paymentMethods[$id] = new Service($id, $configuration); + } + + return $paymentMethods; + } + + private function createEvent(string $provider): PaymentEvent + { + $payment = new Payment(); + $payment->setProvider($provider); + + $orderItem = new OrderItem(); + $orderItem->setPayment($payment); + + return new PaymentEvent($this->cart, $orderItem, self::SETTINGS); + } +} diff --git a/Tests/Unit/EventListener/Order/Payment/ProviderRedirectTest.php b/Tests/Unit/EventListener/Order/Payment/ProviderRedirectTest.php new file mode 100644 index 0000000..de4b5b0 --- /dev/null +++ b/Tests/Unit/EventListener/Order/Payment/ProviderRedirectTest.php @@ -0,0 +1,147 @@ +persistenceManager = $this->createMock(PersistenceManager::class); + $this->cartRepository = $this->createMock(CartRepository::class); + $this->paymentRepository = $this->createMock(PaymentRepository::class); + + $site = self::createStub(Site::class); + $site->method('getRouter')->willReturn(self::createStub(RouterInterface::class)); + + $this->siteFinder = $this->createMock(SiteFinder::class); + $this->siteFinder->method('getSiteByPageId')->willReturn($site); + } + + #[Test] + public function usesTheSiteOfTheCartPage(): void + { + $this->siteFinder + ->expects(self::once()) + ->method('getSiteByPageId') + ->with(3); + + $this->createSubject(); + } + + public static function otherProviderDataProvider(): \Generator + { + yield 'no provider' => ['']; + yield 'provider of another extension' => ['PAYPAL']; + yield 'provider of another extension with clearing type' => ['PAYONE_CREDITCARD']; + } + + #[Test] + #[DataProvider('otherProviderDataProvider')] + public function doesNothingForPaymentsOfOtherProviders(string $provider): void + { + $this->cartRepository->expects(self::never())->method('add'); + $this->paymentRepository->expects(self::never())->method('update'); + $this->persistenceManager->expects(self::never())->method('persistAll'); + + $event = $this->createEvent($provider); + + ($this->createSubject())($event); + + self::assertFalse($event->isPropagationStopped()); + } + + #[Test] + public function throwsExceptionForUnknownClearingType(): void + { + $this->cartRepository->expects(self::never())->method('add'); + + $this->expectExceptionObject(new \InvalidArgumentException('Invalid Clearint Type', 1734099627)); + + ($this->createSubject())($this->createEvent('GIROSOLUTION_UNKNOWN')); + } + + private function createSubject(): ProviderRedirect + { + $configurationManager = self::createStub(ConfigurationManager::class); + $configurationManager + ->method('getConfiguration') + ->willReturnMap([ + [ + ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, + 'CartGirosolution', + null, + ['redirectTypeNum' => '2278106'], + ], + [ + ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, + 'Cart', + null, + ['settings' => ['cart' => ['pid' => '3'], 'order' => ['pid' => '4']]], + ], + ]); + + return new ProviderRedirect( + $configurationManager, + $this->persistenceManager, + $this->siteFinder, + $this->cartRepository, + $this->paymentRepository, + new CredentialLoaderRegistry([]), + ); + } + + private function createEvent(string $provider): PaymentEvent + { + $payment = new Payment(); + $payment->setProvider($provider); + + $orderItem = new OrderItem(); + $orderItem->setPayment($payment); + + return new PaymentEvent(self::createStub(Cart::class), $orderItem); + } +} diff --git a/composer.json b/composer.json index a0ae2d8..bd19cdb 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "Shopping Cart(s) for TYPO3 - Girosolution Payment Provider", "homepage": "https://cart.extco.de", "license": [ - "GPL-2.0+" + "GPL-2.0-or-later" ], "keywords": [ "TYPO3 CMS", @@ -28,30 +28,60 @@ "Extcode\\CartGirosolution\\": "Classes" } }, + "autoload-dev": { + "psr-4": { + "Extcode\\CartGirosolution\\Tests\\": "Tests/", + "Extcode\\GirosolutionTest\\": "Tests/Functional/Fixtures/Extensions/girosolution_test/Classes/" + } + }, "config": { + "bin-dir": ".Build/bin", + "vendor-dir": ".Build/vendor", "allow-plugins": { "typo3/cms-composer-installers": true, "typo3/class-alias-loader": true - } + }, + "lock": false }, "extra": { "typo3/cms": { "extension-key": "cart_girosolution", - "web-dir": ".build/public" + "web-dir": ".Build/public" } }, "require": { "php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0", - "extcode/cart": "^11.0", + "extcode/cart": "^12.0", "girosolution/girocheckout-sdk": "^2.6", - "typo3/cms-core": "^13.4", - "typo3/cms-extbase": "^13.4", - "typo3/cms-fluid": "^13.4" + "typo3/cms-core": "^14.3", + "typo3/cms-extbase": "^14.3", + "typo3/cms-fluid": "^14.3" }, "require-dev": { + "codappix/typo3-php-datasets": "^2.1", "friendsofphp/php-cs-fixer": "^3.64", "helmich/typo3-typoscript-lint": "^3.1", "phpstan/phpstan": "^2.1", - "ssch/typo3-rector": "^3.13" + "phpunit/phpcov": "^10.0 || ^11.0 || ^12.0", + "ssch/typo3-rector": "^3.13", + "typo3/testing-framework": "^9.5" + }, + "scripts": { + "project:cgl": "Build/Scripts/cgl.sh", + "project:cgl:fix": "Build/Scripts/cgl.sh --fix", + "project:lint": [ + "@project:lint:php", + "@project:lint:typoscript", + "@project:lint:xml", + "@project:lint:yaml" + ], + "project:lint:php": "Build/Scripts/lint-php.sh", + "project:lint:typoscript": "Build/Scripts/lint-typoscript.sh", + "project:lint:xml": "Build/Scripts/lint-xml.sh", + "project:lint:yaml": "Build/Scripts/lint-yaml.sh", + "project:phpstan": "Build/Scripts/phpstan.sh", + "project:test:unit": "Build/Scripts/phpunit.sh unit", + "project:test:functional": "Build/Scripts/phpunit.sh functional", + "project:test:coverage": "Build/Scripts/coverage.sh" } } diff --git a/ext_emconf.php b/ext_emconf.php deleted file mode 100644 index 8be7d58..0000000 --- a/ext_emconf.php +++ /dev/null @@ -1,20 +0,0 @@ - 'Cart - Girosolution', - 'description' => 'Shopping Cart(s) for TYPO3 - Girosolution Payment Provider', - 'category' => 'services', - 'author' => 'Daniel Gohlke', - 'author_email' => 'ext@extco.de', - 'author_company' => 'extco.de UG (haftungsbeschränkt)', - 'state' => 'stable', - 'version' => '6.0.0', - 'constraints' => [ - 'depends' => [ - 'typo3' => '13.4.0-13.4.99', - 'cart' => '10.0.0', - ], - 'conflicts' => [], - 'suggests' => [], - ], -]; diff --git a/ext_localconf.php b/ext_localconf.php index dded661..6d93106 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,5 +1,7 @@ 'redirect, notify', - ], - ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT + ] ); // exclude parameters from cHash diff --git a/rector.php b/rector.php index 75f141d..aaaff08 100644 --- a/rector.php +++ b/rector.php @@ -8,7 +8,6 @@ use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; use Rector\ValueObject\PhpVersion; use Ssch\TYPO3Rector\CodeQuality\General\ConvertImplicitVariablesToExplicitGlobalsRector; -use Ssch\TYPO3Rector\CodeQuality\General\ExtEmConfRector; use Ssch\TYPO3Rector\CodeQuality\General\InjectMethodToConstructorInjectionRector; use Ssch\TYPO3Rector\Configuration\Typo3Option; use Ssch\TYPO3Rector\Set\Typo3LevelSetList; @@ -19,7 +18,6 @@ ->withPaths([ __DIR__ . '/Classes', __DIR__ . '/Configuration', - __DIR__ . '/ext_emconf.php', __DIR__ . '/ext_localconf.php', ]) // uncomment to reach your current PHP version @@ -28,7 +26,7 @@ ->withSets([ Typo3SetList::CODE_QUALITY, Typo3SetList::GENERAL, - Typo3LevelSetList::UP_TO_TYPO3_13, + Typo3LevelSetList::UP_TO_TYPO3_14, ]) // To have a better analysis from PHPStan, we teach it here some more things ->withPHPStanConfigs([ @@ -38,11 +36,6 @@ AddVoidReturnTypeWhereNoReturnRector::class, ConvertImplicitVariablesToExplicitGlobalsRector::class, ]) - ->withConfiguredRule(ExtEmConfRector::class, [ - ExtEmConfRector::PHP_VERSION_CONSTRAINT => '8.1.0-8.4.99', - ExtEmConfRector::TYPO3_VERSION_CONSTRAINT => '13.4.0-13.4.99', - ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [], - ]) // If you use withImportNames(), you should consider excluding some TYPO3 files. ->withSkip([ // @see https://github.com/sabbelasichon/typo3-rector/issues/2536 diff --git a/shell.nix b/shell.nix index bd1da45..7722982 100644 --- a/shell.nix +++ b/shell.nix @@ -23,7 +23,7 @@ let composer ]; text = '' - rm -rf .Build/ vendor/ composer.lock + rm -rf .Build/ composer.lock composer update --prefer-dist --no-progress --working-dir="$PROJECT_ROOT" ''; }; @@ -36,7 +36,7 @@ let ]; text = '' - ./vendor/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --diff + "$PROJECT_ROOT/Build/Scripts/cgl.sh" ''; }; @@ -48,7 +48,55 @@ let ]; text = '' - ./vendor/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php + "$PROJECT_ROOT/Build/Scripts/cgl.sh" --fix + ''; + }; + + projectLintPhp = pkgs.writeShellApplication { + name = "project-lint-php"; + + runtimeInputs = [ + php + ]; + + text = '' + "$PROJECT_ROOT/Build/Scripts/lint-php.sh" + ''; + }; + + projectLintTypoScript = pkgs.writeShellApplication { + name = "project-lint-typoscript"; + + runtimeInputs = [ + php + ]; + + text = '' + "$PROJECT_ROOT/Build/Scripts/lint-typoscript.sh" + ''; + }; + + projectLintXml = pkgs.writeShellApplication { + name = "project-lint-xml"; + + runtimeInputs = [ + pkgs.libxml2 + ]; + + text = '' + "$PROJECT_ROOT/Build/Scripts/lint-xml.sh" + ''; + }; + + projectLintYaml = pkgs.writeShellApplication { + name = "project-lint-yaml"; + + runtimeInputs = [ + pkgs.yamllint + ]; + + text = '' + "$PROJECT_ROOT/Build/Scripts/lint-yaml.sh" ''; }; @@ -56,11 +104,17 @@ let name = "project-lint"; runtimeInputs = [ - php + projectLintPhp + projectLintTypoScript + projectLintXml + projectLintYaml ]; text = '' - find ./*.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l + project-lint-php + project-lint-typoscript + project-lint-xml + project-lint-yaml ''; }; @@ -72,25 +126,63 @@ let ]; text = '' - ./vendor/bin/phpstan analyse -c Build/phpstan.neon --memory-limit 256M + "$PROJECT_ROOT/Build/Scripts/phpstan.sh" + ''; + }; + + projectTestUnit = pkgs.writeShellApplication { + name = "project-test-unit"; + runtimeInputs = [ + php + ]; + text = '' + "$PROJECT_ROOT/Build/Scripts/phpunit.sh" unit + ''; + }; + + projectTestFunctional = pkgs.writeShellApplication { + name = "project-test-functional"; + runtimeInputs = [ + php + ]; + text = '' + "$PROJECT_ROOT/Build/Scripts/phpunit.sh" functional + ''; + }; + + projectTestCoverage = pkgs.writeShellApplication { + name = "project-test-coverage"; + runtimeInputs = [ + php + ]; + text = '' + "$PROJECT_ROOT/Build/Scripts/coverage.sh" "$@" ''; }; in pkgs.mkShellNoCC { - name = "TYPO3 Extension extcode/cart-products"; + name = "TYPO3 Extension extcode/cart-girosolution"; buildInputs = [ + pkgs.cacert + pkgs.libxml2 + pkgs.yamllint php composer projectInstall projectCgl projectCglFix projectLint + projectLintPhp + projectLintTypoScript + projectLintXml + projectLintYaml projectPhpstan + projectTestUnit + projectTestFunctional + projectTestCoverage ]; shellHook = '' export PROJECT_ROOT="$(pwd)" - - export typo3DatabaseDriver=pdo_sqlite ''; }