From 8f525e98f2a0f9c42ca4f96e2ed1f445ab5574be Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Mon, 9 Nov 2026 09:07:29 +0100 Subject: [PATCH 01/20] [TASK] Add TYPO3 v14 support --- .github/workflows/ci.yaml | 8 ++++---- Build/phpstan.neon | 1 - .../EventListener/Order/Payment/ClearCart.php | 10 +++------- README.md | 7 ++++--- composer.json | 8 ++++---- ext_emconf.php | 20 ------------------- ext_localconf.php | 3 +-- rector.php | 9 +-------- 8 files changed, 17 insertions(+), 49 deletions(-) delete mode 100644 ext_emconf.php diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a720543..b9d6565 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -71,13 +71,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 diff --git a/Build/phpstan.neon b/Build/phpstan.neon index 871d987..dc850d8 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -5,5 +5,4 @@ parameters: paths: - ../Classes - ../Configuration - - ../ext_emconf.php - ../ext_localconf.php diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index ab4650c..d25aa33 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,11 +39,7 @@ public function __invoke(PaymentEvent $event): void $paymentId = $cart->getPayment()->getId(); - if (!method_exists($this->paymentMethodsService, 'getConfigurationsForType')) { - return; - } - - $paymentSettings = $this->paymentMethodsService->getConfigurationsForType('payments', $cart->getBillingCountry()); + $paymentSettings = $this->paymentMethodsLoader->getPaymentMethods($cart); if ((int)($paymentSettings['options'][$paymentId]['preventClearCart'] ?? 0) != 1) { $cartPid = $settings['settings']['cart']['pid']; diff --git a/README.md b/README.md index e6a30ea..366a31a 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,10 @@ The extension can only be installed via composer. Installation via the TER is no | 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 | +| 7.x.x | 14.3 | 8.2+ | Features, Bugfixes, Security Updates | +| 6.x.x | 13.4 | 8.2+ | 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 | | diff --git a/composer.json b/composer.json index a0ae2d8..0796dbc 100644 --- a/composer.json +++ b/composer.json @@ -42,11 +42,11 @@ }, "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": { "friendsofphp/php-cs-fixer": "^3.64", 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..8f28bb2 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -15,8 +15,7 @@ ], [ PaymentController::class => '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 From 51619839fb4c718c3dd0c7f1ffcf7640540ae0fb Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 11:12:27 +0100 Subject: [PATCH 02/20] [TASK] Use .Build as build directory Composer installs the dependencies, the binaries and the TYPO3 instance into .Build/ now, like all other cart extensions. composer.lock is disabled, so every install resolves the latest allowed versions. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 4 ++-- .gitignore | 3 +-- composer.json | 7 +++++-- shell.nix | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b9d6565..06c8850 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -61,7 +61,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/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --using-cache=no --path-mode=intersection ./ code-quality: runs-on: ubuntu-latest @@ -92,4 +92,4 @@ 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/bin/phpstan analyse -c Build/phpstan.neon 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/composer.json b/composer.json index 0796dbc..7ecff38 100644 --- a/composer.json +++ b/composer.json @@ -29,15 +29,18 @@ } }, "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": { diff --git a/shell.nix b/shell.nix index bd1da45..431ce0d 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 + ./.Build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php -v --dry-run --diff ''; }; @@ -48,7 +48,7 @@ let ]; text = '' - ./vendor/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php + ./.Build/bin/php-cs-fixer fix --config=Build/.php-cs-fixer.dist.php ''; }; @@ -72,7 +72,7 @@ let ]; text = '' - ./vendor/bin/phpstan analyse -c Build/phpstan.neon --memory-limit 256M + ./.Build/bin/phpstan analyse -c Build/phpstan.neon --memory-limit 256M ''; }; From 7cae7ff3ea2cd65eb1fc742e5b86d7ef07023339 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 11:13:32 +0100 Subject: [PATCH 03/20] [TASK] Refactor tests to Build/Scripts directory The tests should be executable for local testing and GitHub Actions with nearly the same context. The composer scripts, the nix-shell commands and the CI workflow now call the same scripts in Build/Scripts, which also lift the PHP memory limit. The extension has no unit, functional or acceptance tests, so there are no scripts for them yet. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 6 +++--- Build/Scripts/cgl.sh | 20 ++++++++++++++++++++ Build/Scripts/common.sh | 35 +++++++++++++++++++++++++++++++++++ Build/Scripts/lint-php.sh | 11 +++++++++++ Build/Scripts/phpstan.sh | 12 ++++++++++++ composer.json | 9 +++++++++ shell.nix | 28 ++++++++++++++++++++-------- 7 files changed, 110 insertions(+), 11 deletions(-) create mode 100755 Build/Scripts/cgl.sh create mode 100644 Build/Scripts/common.sh create mode 100755 Build/Scripts/lint-php.sh create mode 100755 Build/Scripts/phpstan.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 06c8850..c1369ba 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,7 @@ 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 documentation-rendering: runs-on: ubuntu-latest @@ -61,7 +61,7 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Coding Guideline - run: .Build/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 @@ -92,4 +92,4 @@ 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: .Build/bin/phpstan analyse -c Build/phpstan.neon + run: Build/Scripts/phpstan.sh 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/lint-php.sh b/Build/Scripts/lint-php.sh new file mode 100755 index 0000000..b954914 --- /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 -name '*.php' -print0 \ + | xargs -0 -n 1 -P 4 "${PHP_BIN}" -l 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/composer.json b/composer.json index 7ecff38..1f4bb63 100644 --- a/composer.json +++ b/composer.json @@ -56,5 +56,14 @@ "helmich/typo3-typoscript-lint": "^3.1", "phpstan/phpstan": "^2.1", "ssch/typo3-rector": "^3.13" + }, + "scripts": { + "project:cgl": "Build/Scripts/cgl.sh", + "project:cgl:fix": "Build/Scripts/cgl.sh --fix", + "project:lint": [ + "@project:lint:php" + ], + "project:lint:php": "Build/Scripts/lint-php.sh", + "project:phpstan": "Build/Scripts/phpstan.sh" } } diff --git a/shell.nix b/shell.nix index 431ce0d..b40ef5a 100644 --- a/shell.nix +++ b/shell.nix @@ -36,7 +36,7 @@ let ]; text = '' - ./.Build/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,19 @@ let ]; text = '' - ./.Build/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" ''; }; @@ -56,11 +68,11 @@ let name = "project-lint"; runtimeInputs = [ - php + projectLintPhp ]; text = '' - find ./*.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l + project-lint-php ''; }; @@ -72,25 +84,25 @@ let ]; text = '' - ./.Build/bin/phpstan analyse -c Build/phpstan.neon --memory-limit 256M + "$PROJECT_ROOT/Build/Scripts/phpstan.sh" ''; }; in pkgs.mkShellNoCC { - name = "TYPO3 Extension extcode/cart-products"; + name = "TYPO3 Extension extcode/cart-girosolution"; buildInputs = [ + pkgs.cacert php composer projectInstall projectCgl projectCglFix projectLint + projectLintPhp projectPhpstan ]; shellHook = '' export PROJECT_ROOT="$(pwd)" - - export typo3DatabaseDriver=pdo_sqlite ''; } From 0a9cca69328f51db55d36a8f5860fbef21f58f77 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 11:14:05 +0100 Subject: [PATCH 04/20] [TASK] Run yaml lint via Build/Scripts Build/yamllint.yaml existed but was not used. Build/Scripts/lint-yaml.sh lints all yaml files except the ones ignored by .gitignore. It is available as composer script project:lint:yaml, as project-lint-yaml in shell.nix and runs in the GitHub CI. The truthy rule no longer checks keys, so the "on" key of GitHub workflows is allowed. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 12 ++++++++++++ Build/Scripts/lint-yaml.sh | 19 +++++++++++++++++++ Build/typoscriptlint.yaml | 2 +- Build/yamllint.yaml | 6 +++++- composer.json | 4 +++- shell.nix | 16 ++++++++++++++++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100755 Build/Scripts/lint-yaml.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c1369ba..2284bcb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,6 +32,18 @@ jobs: - name: PHP lint run: Build/Scripts/lint-php.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 steps: 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/typoscriptlint.yaml b/Build/typoscriptlint.yaml index 12405ea..d48586c 100644 --- a/Build/typoscriptlint.yaml +++ b/Build/typoscriptlint.yaml @@ -16,4 +16,4 @@ sniffs: parameters: commonPathPrefixThreshold: 1 filePatterns: - - "*.typoscript" \ No newline at end of file + - "*.typoscript" 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/composer.json b/composer.json index 1f4bb63..81d1f79 100644 --- a/composer.json +++ b/composer.json @@ -61,9 +61,11 @@ "project:cgl": "Build/Scripts/cgl.sh", "project:cgl:fix": "Build/Scripts/cgl.sh --fix", "project:lint": [ - "@project:lint:php" + "@project:lint:php", + "@project:lint:yaml" ], "project:lint:php": "Build/Scripts/lint-php.sh", + "project:lint:yaml": "Build/Scripts/lint-yaml.sh", "project:phpstan": "Build/Scripts/phpstan.sh" } } diff --git a/shell.nix b/shell.nix index b40ef5a..f584d66 100644 --- a/shell.nix +++ b/shell.nix @@ -64,15 +64,29 @@ let ''; }; + projectLintYaml = pkgs.writeShellApplication { + name = "project-lint-yaml"; + + runtimeInputs = [ + pkgs.yamllint + ]; + + text = '' + "$PROJECT_ROOT/Build/Scripts/lint-yaml.sh" + ''; + }; + projectLint = pkgs.writeShellApplication { name = "project-lint"; runtimeInputs = [ projectLintPhp + projectLintYaml ]; text = '' project-lint-php + project-lint-yaml ''; }; @@ -92,6 +106,7 @@ in pkgs.mkShellNoCC { name = "TYPO3 Extension extcode/cart-girosolution"; buildInputs = [ pkgs.cacert + pkgs.yamllint php composer projectInstall @@ -99,6 +114,7 @@ in pkgs.mkShellNoCC { projectCglFix projectLint projectLintPhp + projectLintYaml projectPhpstan ]; From fc8fa0170303450c05b1c5bf5047849a2b319770 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 11:14:38 +0100 Subject: [PATCH 05/20] [TASK] Run xml lint via Build/Scripts Build/Scripts/lint-xml.sh validates the XLIFF files against the XLIFF 1.2 strict schema. Both schemas used for XLIFF are stored in Build/, so the validation does not need to download xml.xsd from w3.org. It is available as composer script project:lint:xml, as project-lint-xml in shell.nix and runs in the GitHub CI. The XLIFF file uses version 1.2 with its namespace now. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 12 + Build/Scripts/lint-xml.sh | 22 + Build/xliff-core-1.2-strict.xsd | 2223 ++++++++++++++++++++++ Build/xml.xsd | 287 +++ Resources/Private/Language/locallang.xlf | 2 +- composer.json | 2 + shell.nix | 16 + 7 files changed, 2563 insertions(+), 1 deletion(-) create mode 100755 Build/Scripts/lint-xml.sh create mode 100644 Build/xliff-core-1.2-strict.xsd create mode 100644 Build/xml.xsd diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2284bcb..7c78491 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,6 +32,18 @@ jobs: - name: PHP lint run: Build/Scripts/lint-php.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: XML lint + run: Build/Scripts/lint-xml.sh + yaml-linting: runs-on: ubuntu-latest steps: diff --git a/Build/Scripts/lint-xml.sh b/Build/Scripts/lint-xml.sh new file mode 100755 index 0000000..9766e04 --- /dev/null +++ b/Build/Scripts/lint-xml.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Validates the XLIFF files in Resources/Private/Language against XLIFF 1.2 +# strict (Build/xliff-core-1.2-strict.xsd, imports Build/xml.xsd). +# +# 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 + +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 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/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/composer.json b/composer.json index 81d1f79..819609d 100644 --- a/composer.json +++ b/composer.json @@ -62,9 +62,11 @@ "project:cgl:fix": "Build/Scripts/cgl.sh --fix", "project:lint": [ "@project:lint:php", + "@project:lint:xml", "@project:lint:yaml" ], "project:lint:php": "Build/Scripts/lint-php.sh", + "project:lint:xml": "Build/Scripts/lint-xml.sh", "project:lint:yaml": "Build/Scripts/lint-yaml.sh", "project:phpstan": "Build/Scripts/phpstan.sh" } diff --git a/shell.nix b/shell.nix index f584d66..3e34c42 100644 --- a/shell.nix +++ b/shell.nix @@ -64,6 +64,18 @@ let ''; }; + 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"; @@ -81,11 +93,13 @@ let runtimeInputs = [ projectLintPhp + projectLintXml projectLintYaml ]; text = '' project-lint-php + project-lint-xml project-lint-yaml ''; }; @@ -106,6 +120,7 @@ in pkgs.mkShellNoCC { name = "TYPO3 Extension extcode/cart-girosolution"; buildInputs = [ pkgs.cacert + pkgs.libxml2 pkgs.yamllint php composer @@ -114,6 +129,7 @@ in pkgs.mkShellNoCC { projectCglFix projectLint projectLintPhp + projectLintXml projectLintYaml projectPhpstan ]; From 623c58a40afbe4b13d0af17a4451b977d642b2c1 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 11:15:17 +0100 Subject: [PATCH 06/20] [TASK] Run TypoScript lint via Build/Scripts Build/Scripts/lint-typoscript.sh lints the TypoScript and TSconfig files in Configuration with Build/typoscriptlint.yaml and fails on warnings. It is available as composer script project:lint:typoscript, as project-lint-typoscript in shell.nix and runs in the GitHub CI. The content of conditions is indented now, RepeatingRValue is disabled because extracting repeated values into constants would add them to the public configuration of the extension. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yaml | 18 ++++++++++++++++++ Build/Scripts/lint-typoscript.sh | 21 +++++++++++++++++++++ Build/typoscriptlint.yaml | 9 +++++---- Configuration/TypoScript/setup.typoscript | 6 ++++-- composer.json | 2 ++ shell.nix | 15 +++++++++++++++ 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100755 Build/Scripts/lint-typoscript.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7c78491..75c6453 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,6 +32,24 @@ jobs: - name: PHP lint 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: 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/typoscriptlint.yaml b/Build/typoscriptlint.yaml index d48586c..6b7e404 100644 --- a/Build/typoscriptlint.yaml +++ b/Build/typoscriptlint.yaml @@ -3,13 +3,13 @@ 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 @@ -17,3 +17,4 @@ sniffs: commonPathPrefixThreshold: 1 filePatterns: - "*.typoscript" + - "*.tsconfig" diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index dbe975e..ca24bd6 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -11,8 +11,10 @@ cartGirosolution { } 10 = EXTBASEPLUGIN - 10.extensionName = CartGirosolution - 10.pluginName = Cart + 10 { + extensionName = CartGirosolution + pluginName = Cart + } } plugin.tx_cartgirosolution { diff --git a/composer.json b/composer.json index 819609d..09a3f92 100644 --- a/composer.json +++ b/composer.json @@ -62,10 +62,12 @@ "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" diff --git a/shell.nix b/shell.nix index 3e34c42..0c0ad43 100644 --- a/shell.nix +++ b/shell.nix @@ -64,6 +64,18 @@ let ''; }; + projectLintTypoScript = pkgs.writeShellApplication { + name = "project-lint-typoscript"; + + runtimeInputs = [ + php + ]; + + text = '' + "$PROJECT_ROOT/Build/Scripts/lint-typoscript.sh" + ''; + }; + projectLintXml = pkgs.writeShellApplication { name = "project-lint-xml"; @@ -93,12 +105,14 @@ let runtimeInputs = [ projectLintPhp + projectLintTypoScript projectLintXml projectLintYaml ]; text = '' project-lint-php + project-lint-typoscript project-lint-xml project-lint-yaml ''; @@ -129,6 +143,7 @@ in pkgs.mkShellNoCC { projectCglFix projectLint projectLintPhp + projectLintTypoScript projectLintXml projectLintYaml projectPhpstan From 75383c38db23f09156b8c624772d3dddd00b966a Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 11:16:44 +0100 Subject: [PATCH 07/20] [TASK] Use valid SPDX license identifier GPL-2.0+ is a deprecated SPDX license identifier, composer validate recommends GPL-2.0-or-later instead. Co-Authored-By: Claude Opus 5.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 09a3f92..9dac4ac 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", From 34417cd612918d8dc29dc21f94f7df01e35f7b5b Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 11:42:16 +0100 Subject: [PATCH 08/20] [DOCS] Document supported versions The table of supported versions was part of the README of every branch. The support status changes over time, but the README of older branches is not updated, so it showed an outdated status. The table is maintained in the documentation of the main branch now, and the READMEs of all branches link to it. SECURITY.md on the main branch describes which versions get security updates and that vulnerabilities are reported to the TYPO3 Security Team. GitHub shows the file in the security tab of the repository. The README is aligned with the other cart extensions: - It links to the extension documentation, also for the installation. - The release management section is removed, it was copied from another extension and named it instead of this one. - The changelog link points to the current documentation URL. - The headings use consistent levels and numbering. Co-Authored-By: Claude Opus 5.5 --- Documentation/Introduction/Index.rst | 1 + .../Introduction/SupportedVersions/Index.rst | 32 +++++++++++++++ README.md | 41 ++++++------------- SECURITY.md | 15 +++++++ 4 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 Documentation/Introduction/SupportedVersions/Index.rst create mode 100644 SECURITY.md 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 366a31a..cee4914 100644 --- a/README.md +++ b/README.md @@ -3,53 +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 | -|-------------------|------------|-----------|--------------------------------------| -| 7.x.x | 14.3 | 8.2+ | Features, Bugfixes, Security Updates | -| 6.x.x | 13.4 | 8.2+ | 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 | | +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/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. From 86d81f64998ed9f5f5eb1df0fa20802cb8fbba7e Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 12:01:10 +0100 Subject: [PATCH 09/20] [BUGFIX] Ignore payment providers without clearing type The ProviderRedirect listener splits the provider of every payment into provider and clearing type. Providers of other extensions without an underscore, e.g. PAYPAL of cart_paypal, caused the warning "Undefined array key 1". The missing clearing type defaults to an empty string now, like in the PaymentController. Co-Authored-By: Claude Opus 5.5 --- Classes/EventListener/Order/Payment/ProviderRedirect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 0292d828d84d88867124ba6937cc6bcd01f04144 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 12:01:10 +0100 Subject: [PATCH 10/20] [BUGFIX] Respond to payment notification without template Girosolution calls the notifyAction after a payment and only expects the HTTP status. The action rendered a template that does not exist, so the request failed after the payment had been updated, and Girosolution retried the notification. The action returns an empty response now. Co-Authored-By: Claude Opus 5.5 --- Classes/Controller/Order/PaymentController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index b484f5e..bb8d52e 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -143,7 +143,7 @@ public function notifyAction(): ResponseInterface } $notify->sendOkStatus(); - return $this->htmlResponse(); + return $this->htmlResponse(''); } private function updatePaymentAndTransaction($notify, Item $orderItem, string $status): bool From 33ee4c628dbb2bad5c1cf534a55bb0306d9c6f8f Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 12:03:51 +0100 Subject: [PATCH 11/20] [BUGFIX] Respect preventClearCart of the payment method Since TYPO3 v14 the PaymentMethodsLoaderInterface returns the payment methods as services indexed by their id instead of the TypoScript configuration. The ClearCart listener still looked for options..preventClearCart in the result, so the cart was always cleared. The option is read from the configuration of the service now. Co-Authored-By: Claude Opus 5.5 --- Classes/EventListener/Order/Payment/ClearCart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index d25aa33..f24ceab 100644 --- a/Classes/EventListener/Order/Payment/ClearCart.php +++ b/Classes/EventListener/Order/Payment/ClearCart.php @@ -39,9 +39,9 @@ public function __invoke(PaymentEvent $event): void $paymentId = $cart->getPayment()->getId(); - $paymentSettings = $this->paymentMethodsLoader->getPaymentMethods($cart); + $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( From 8374e015ceed900921c6539df1536f40f6744c88 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 12:03:51 +0100 Subject: [PATCH 12/20] [TASK] Add unit and functional tests The extension had no tests so far. The setup follows the other cart extensions: Build/phpunit.xml.dist with the testsuites unit and functional, run via Build/Scripts/phpunit.sh, the composer scripts project:test:unit and project:test:functional, the commands project-test-unit and project-test-functional in shell.nix and a CI job for all supported PHP versions. The tests are linted and analysed by PHPStan as well, Build/phpunit.xml.dist is validated by the xml lint. The unit tests cover the credential loaders, the events and the event listeners as far as they do not need the API of Girosolution. The functional tests send the notification of Girosolution to the frontend and check the stored payment and transaction and the dispatched events for successful and canceled payments, for repeated notifications, for a wrong hash and an unknown cart. They also verify that credentials from TYPO3_CONF_VARS override the ones from TypoScript. The events are recorded by the listener of the test extension girosolution_test, as frontend requests use their own listener provider. Co-Authored-By: Claude Opus 5.5 --- .gitattributes | 3 +- .github/workflows/ci.yaml | 39 ++++ Build/Scripts/lint-php.sh | 2 +- Build/Scripts/lint-xml.sh | 9 +- Build/Scripts/phpunit.sh | 57 +++++ Build/phpstan.neon | 1 + Build/phpunit.xml.dist | 33 +++ .../AbstractPaymentControllerTestCase.php | 135 ++++++++++++ .../Order/PaymentControllerTest.php | 131 ++++++++++++ ...trollerWithCredentialsFromConfVarsTest.php | 61 ++++++ Tests/Functional/Fixtures/DataSets/Base.php | 49 +++++ Tests/Functional/Fixtures/DataSets/Order.php | 37 ++++ .../Classes/EventListener/EventRecorder.php | 45 ++++ .../Configuration/Services.yaml | 14 ++ .../girosolution_test/composer.json | 21 ++ .../Fixtures/Sites/default/config.yaml | 13 ++ .../CredentialLoaderRegistryTest.php | 129 +++++++++++ .../CredentialsFromConfVarsTest.php | 100 +++++++++ .../CredentialsFromTypoScriptTest.php | 90 ++++++++ Tests/Unit/Event/Order/CancelEventTest.php | 92 ++++++++ Tests/Unit/Event/Order/FinishEventTest.php | 92 ++++++++ .../Order/Payment/ClearCartTest.php | 202 ++++++++++++++++++ .../Order/Payment/ProviderRedirectTest.php | 147 +++++++++++++ composer.json | 14 +- shell.nix | 22 ++ 25 files changed, 1532 insertions(+), 6 deletions(-) create mode 100755 Build/Scripts/phpunit.sh create mode 100644 Build/phpunit.xml.dist create mode 100644 Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php create mode 100644 Tests/Functional/Controller/Order/PaymentControllerTest.php create mode 100644 Tests/Functional/Controller/Order/PaymentControllerWithCredentialsFromConfVarsTest.php create mode 100644 Tests/Functional/Fixtures/DataSets/Base.php create mode 100644 Tests/Functional/Fixtures/DataSets/Order.php create mode 100644 Tests/Functional/Fixtures/Extensions/girosolution_test/Classes/EventListener/EventRecorder.php create mode 100644 Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.yaml create mode 100644 Tests/Functional/Fixtures/Extensions/girosolution_test/composer.json create mode 100644 Tests/Functional/Fixtures/Sites/default/config.yaml create mode 100644 Tests/Unit/Configuration/CredentialLoaderRegistryTest.php create mode 100644 Tests/Unit/Configuration/CredentialsFromConfVarsTest.php create mode 100644 Tests/Unit/Configuration/CredentialsFromTypoScriptTest.php create mode 100644 Tests/Unit/Event/Order/CancelEventTest.php create mode 100644 Tests/Unit/Event/Order/FinishEventTest.php create mode 100644 Tests/Unit/EventListener/Order/Payment/ClearCartTest.php create mode 100644 Tests/Unit/EventListener/Order/Payment/ProviderRedirectTest.php 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 75c6453..c32d1b1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -59,6 +59,15 @@ jobs: - 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 @@ -135,3 +144,33 @@ jobs: - name: Code Quality (by PHPStan) 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/Build/Scripts/lint-php.sh b/Build/Scripts/lint-php.sh index b954914..1b86352 100755 --- a/Build/Scripts/lint-php.sh +++ b/Build/Scripts/lint-php.sh @@ -7,5 +7,5 @@ source "$(dirname "${BASH_SOURCE[0]}")/common.sh" -find ./*.php Classes Configuration -name '*.php' -print0 \ +find ./*.php Classes Configuration Tests -name '*.php' -print0 \ | xargs -0 -n 1 -P 4 "${PHP_BIN}" -l diff --git a/Build/Scripts/lint-xml.sh b/Build/Scripts/lint-xml.sh index 9766e04..06b4e08 100755 --- a/Build/Scripts/lint-xml.sh +++ b/Build/Scripts/lint-xml.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash # -# Validates the XLIFF files in Resources/Private/Language against XLIFF 1.2 -# strict (Build/xliff-core-1.2-strict.xsd, imports Build/xml.xsd). +# 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). @@ -15,8 +17,11 @@ 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/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 dc850d8..30b0b9a 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -5,4 +5,5 @@ parameters: paths: - ../Classes - ../Configuration + - ../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/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php b/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php new file mode 100644 index 0000000..bbdf804 --- /dev/null +++ b/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php @@ -0,0 +1,135 @@ + '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'); + + $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(); + } + + protected function sendNotification( + string $resultPayment, + string $secret, + string $cartHash = self::CART_HASH, + ): 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; + + return $this->executeFrontendSubRequest( + (new InternalRequest('http://localhost/')) + ->withPageId(1) + ->withQueryParameters([ + 'type' => 2278106, + 'tx_cartgirosolution_cart[controller]' => 'Order\\Payment', + 'tx_cartgirosolution_cart[action]' => 'notify', + 'tx_cartgirosolution_cart[hash]' => $cartHash, + ] + $notification) + ); + } + + 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/PaymentControllerTest.php b/Tests/Functional/Controller/Order/PaymentControllerTest.php new file mode 100644 index 0000000..5b0ac11 --- /dev/null +++ b/Tests/Functional/Controller/Order/PaymentControllerTest.php @@ -0,0 +1,131 @@ +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 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/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..36972b5 --- /dev/null +++ b/Tests/Functional/Fixtures/DataSets/Base.php @@ -0,0 +1,49 @@ + [ + [ + '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', + '}', + ]), + ], + ], +]; 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.yaml b/Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.yaml new file mode 100644 index 0000000..26ce00e --- /dev/null +++ b/Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.yaml @@ -0,0 +1,14 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + Extcode\GirosolutionTest\EventListener\EventRecorder: + tags: + - name: event.listener + identifier: 'girosolution-test--order--finish--event-recorder' + event: Extcode\CartGirosolution\Event\Order\FinishEvent + - name: event.listener + identifier: 'girosolution-test--order--cancel--event-recorder' + event: Extcode\CartGirosolution\Event\Order\CancelEvent 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 9dac4ac..cd0f1e1 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,12 @@ "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", @@ -52,10 +58,12 @@ "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" + "ssch/typo3-rector": "^3.13", + "typo3/testing-framework": "^9.5" }, "scripts": { "project:cgl": "Build/Scripts/cgl.sh", @@ -70,6 +78,8 @@ "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:phpstan": "Build/Scripts/phpstan.sh", + "project:test:unit": "Build/Scripts/phpunit.sh unit", + "project:test:functional": "Build/Scripts/phpunit.sh functional" } } diff --git a/shell.nix b/shell.nix index 0c0ad43..f2ce065 100644 --- a/shell.nix +++ b/shell.nix @@ -130,6 +130,26 @@ let ''; }; + 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 + ''; + }; + in pkgs.mkShellNoCC { name = "TYPO3 Extension extcode/cart-girosolution"; buildInputs = [ @@ -147,6 +167,8 @@ in pkgs.mkShellNoCC { projectLintXml projectLintYaml projectPhpstan + projectTestUnit + projectTestFunctional ]; shellHook = '' From ec7d5e6b85ac82cee3ea1d2ea9d5730f20603d7c Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 12:41:01 +0100 Subject: [PATCH 13/20] [TASK] Add command to measure the test coverage Build/Scripts/coverage.sh runs every testsuite in its own phpunit process like phpunit.sh, merges the coverage with phpcov, prints the summary and writes the html report to .Build/coverage. It is available as composer script project:test:coverage and as project-test-coverage in shell.nix, which provides php with xdebug. Co-Authored-By: Claude Opus 5.5 --- Build/Scripts/coverage.sh | 63 +++++++++++++++++++++++++++++++++++++++ composer.json | 4 ++- shell.nix | 11 +++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 Build/Scripts/coverage.sh 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/composer.json b/composer.json index cd0f1e1..bd19cdb 100644 --- a/composer.json +++ b/composer.json @@ -62,6 +62,7 @@ "friendsofphp/php-cs-fixer": "^3.64", "helmich/typo3-typoscript-lint": "^3.1", "phpstan/phpstan": "^2.1", + "phpunit/phpcov": "^10.0 || ^11.0 || ^12.0", "ssch/typo3-rector": "^3.13", "typo3/testing-framework": "^9.5" }, @@ -80,6 +81,7 @@ "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:functional": "Build/Scripts/phpunit.sh functional", + "project:test:coverage": "Build/Scripts/coverage.sh" } } diff --git a/shell.nix b/shell.nix index f2ce065..7722982 100644 --- a/shell.nix +++ b/shell.nix @@ -150,6 +150,16 @@ let ''; }; + projectTestCoverage = pkgs.writeShellApplication { + name = "project-test-coverage"; + runtimeInputs = [ + php + ]; + text = '' + "$PROJECT_ROOT/Build/Scripts/coverage.sh" "$@" + ''; + }; + in pkgs.mkShellNoCC { name = "TYPO3 Extension extcode/cart-girosolution"; buildInputs = [ @@ -169,6 +179,7 @@ in pkgs.mkShellNoCC { projectPhpstan projectTestUnit projectTestFunctional + projectTestCoverage ]; shellHook = '' From 0d362ce99dde258d3ebfe5e56d4fc7872f2d8d94 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 12:41:01 +0100 Subject: [PATCH 14/20] [TASK] Add functional tests for the redirect action Girosolution redirects the customer to the redirectAction after the payment. The tests check the redirect to the order or back to the cart, the stored payment and transaction, the dispatched events, the cart and flash message restored in the session after a canceled payment and the rejection of requests with a wrong hash or without cart hash. The tests of the notifyAction are moved to their own class and cover PayPal payments, unknown clearing types and payments without transaction as well. Co-Authored-By: Claude Opus 5.5 --- .../AbstractPaymentControllerTestCase.php | 53 +++- ... => PaymentControllerNotifyActionTest.php} | 73 +++++- .../PaymentControllerRedirectActionTest.php | 226 ++++++++++++++++++ Tests/Functional/Fixtures/DataSets/Base.php | 5 + 4 files changed, 349 insertions(+), 8 deletions(-) rename Tests/Functional/Controller/Order/{PaymentControllerTest.php => PaymentControllerNotifyActionTest.php} (62%) create mode 100644 Tests/Functional/Controller/Order/PaymentControllerRedirectActionTest.php diff --git a/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php b/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php index bbdf804..ffaa220 100644 --- a/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php +++ b/Tests/Functional/Controller/Order/AbstractPaymentControllerTestCase.php @@ -67,6 +67,7 @@ protected function setUp(): void $cart = new Cart([]); $cart->setBillingCountry('de'); + $cart->setOrderNumber('ORD-2026-0001'); $this->get(ConnectionPool::class) ->getConnectionForTable('tx_cart_domain_model_cart') @@ -81,10 +82,38 @@ protected function setUp(): void 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, + ?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, @@ -99,18 +128,28 @@ protected function sendNotification( // 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, - 'tx_cartgirosolution_cart[controller]' => 'Order\\Payment', - 'tx_cartgirosolution_cart[action]' => 'notify', - 'tx_cartgirosolution_cart[hash]' => $cartHash, - ] + $notification) + ->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']); diff --git a/Tests/Functional/Controller/Order/PaymentControllerTest.php b/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php similarity index 62% rename from Tests/Functional/Controller/Order/PaymentControllerTest.php rename to Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php index 5b0ac11..fcc7ee9 100644 --- a/Tests/Functional/Controller/Order/PaymentControllerTest.php +++ b/Tests/Functional/Controller/Order/PaymentControllerNotifyActionTest.php @@ -18,13 +18,14 @@ use girosolution\GiroCheckout_SDK\helper\GiroCheckout_SDK_Exception_helper; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; +use TYPO3\CMS\Core\Database\ConnectionPool; /** * Checks the stored payment, the transaction and the dispatched events after * the notification of Girosolution. */ #[CoversClass(PaymentController::class)] -final class PaymentControllerTest extends AbstractPaymentControllerTestCase +final class PaymentControllerNotifyActionTest extends AbstractPaymentControllerTestCase { #[Test] public function successfulPaymentMarksPaymentAndTransactionAsPaid(): void @@ -120,6 +121,76 @@ public function notificationForUnknownCartIsRejected(): void 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 { 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/Fixtures/DataSets/Base.php b/Tests/Functional/Fixtures/DataSets/Base.php index 36972b5..8526419 100644 --- a/Tests/Functional/Fixtures/DataSets/Base.php +++ b/Tests/Functional/Fixtures/DataSets/Base.php @@ -43,6 +43,11 @@ ' projectId = 5678', ' password = credit-card-secret', '}', + 'plugin.tx_cartgirosolution.credentials.paypal {', + ' merchantId = 1234', + ' projectId = 9012', + ' password = paypal-secret', + '}', ]), ], ], From de99479869f456b5156b150427a1fdc34826cc9e Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 15:22:41 +0100 Subject: [PATCH 15/20] [TASK] Register the event recorder of the tests via Services.php The test extension girosolution_test registers its listener in Services.php instead of Services.yaml. The classes are referenced by their class constants, so a renamed or moved class is found by the IDE and PHPStan. Co-Authored-By: Claude Opus 5.5 --- .../Configuration/Services.php | 28 +++++++++++++++++++ .../Configuration/Services.yaml | 14 ---------- 2 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.php delete mode 100644 Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.yaml 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/Configuration/Services.yaml b/Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.yaml deleted file mode 100644 index 26ce00e..0000000 --- a/Tests/Functional/Fixtures/Extensions/girosolution_test/Configuration/Services.yaml +++ /dev/null @@ -1,14 +0,0 @@ -services: - _defaults: - autowire: true - autoconfigure: true - public: false - - Extcode\GirosolutionTest\EventListener\EventRecorder: - tags: - - name: event.listener - identifier: 'girosolution-test--order--finish--event-recorder' - event: Extcode\CartGirosolution\Event\Order\FinishEvent - - name: event.listener - identifier: 'girosolution-test--order--cancel--event-recorder' - event: Extcode\CartGirosolution\Event\Order\CancelEvent From 1a9ebf02d31119bfe97070a6a9170ff9e89021d0 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 15:49:19 +0100 Subject: [PATCH 16/20] [TASK] Declare strict types in all PHP files The PaymentController, ext_localconf.php and the TCA override were the only PHP files without strict types. The tests cover the controller, so type errors in calls from it are detected now. ext_emconf.php is left untouched, it only returns the configuration for the TYPO3 Extension Repository. Co-Authored-By: Claude Opus 5.5 --- Classes/Controller/Order/PaymentController.php | 2 ++ Configuration/TCA/Overrides/sys_template.php | 2 ++ ext_localconf.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index bb8d52e..722fcd8 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -1,5 +1,7 @@ Date: Sat, 14 Nov 2026 15:53:18 +0100 Subject: [PATCH 17/20] [TASK] Check strict types declaration with php-cs-fixer The rule declare_strict_types reports PHP files without strict types, project:cgl:fix adds the declaration. Co-Authored-By: Claude Opus 5.5 --- Build/.php-cs-fixer.dist.php | 1 + 1 file changed, 1 insertion(+) 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, From 23aa8e81a73f42433ab5500b4a3cf5b13a81174b Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 15:56:58 +0100 Subject: [PATCH 18/20] [TASK] Move service configuration to Services.php The services were configured partly in Services.yaml and partly in Services.php. All services are configured in Services.php now, the classes are referenced by their class constants, so a renamed or moved class is found by the IDE and PHPStan. A functional test checks the registered event listeners and that the cart is cleared before the customer is redirected to Girosolution. Co-Authored-By: Claude Opus 5.5 --- Configuration/Services.php | 41 ++++++++--- Configuration/Services.yaml | 30 -------- .../EventListenerRegistrationTest.php | 73 +++++++++++++++++++ 3 files changed, 105 insertions(+), 39 deletions(-) delete mode 100644 Configuration/Services.yaml create mode 100644 Tests/Functional/Configuration/EventListenerRegistrationTest.php diff --git a/Configuration/Services.php b/Configuration/Services.php index c3e4176..7743ce2 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('Extcode\\CartGirosolution\\EventListener\\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/Tests/Functional/Configuration/EventListenerRegistrationTest.php b/Tests/Functional/Configuration/EventListenerRegistrationTest.php new file mode 100644 index 0000000..3f3fae3 --- /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( + 'Extcode\\CartGirosolution\\EventListener\\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] ?? []; + } +} From fe25243ffadcca516907ceee9f7566d98bfc84b0 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 16:18:00 +0100 Subject: [PATCH 19/20] [TASK] Use a descriptive service id for the email listener The email listener of cart is registered a second time for the FinishEvent of this extension, because the FinishEvent of cart is not dispatched for payments with Girosolution. The service id looked like a class of this extension that does not exist. It is a descriptive id now, the class of the service is the listener of cart. The identifier of the event listener is unchanged. The change is documented as breaking change in the changelog of 6.0, the release which introduces it. The changelog of 7.0 is added as well. Co-Authored-By: Claude Opus 5.5 --- Configuration/Services.php | 2 +- ...king-33-RenameServiceIdOfEmailListener.rst | 39 +++++++++++++++++++ Documentation/Changelog/6.0/Index.rst | 18 ++++++++- Documentation/Changelog/7.0/Index.rst | 7 ++++ Documentation/Changelog/Index.rst | 1 + .../EventListenerRegistrationTest.php | 2 +- 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 Documentation/Changelog/6.0/Breaking-33-RenameServiceIdOfEmailListener.rst create mode 100644 Documentation/Changelog/7.0/Index.rst diff --git a/Configuration/Services.php b/Configuration/Services.php index 7743ce2..1e7d972 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -46,7 +46,7 @@ 'event' => PaymentEvent::class, ]); - $services->set('Extcode\\CartGirosolution\\EventListener\\Order\\Finish\\Email', Email::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/Documentation/Changelog/6.0/Breaking-33-RenameServiceIdOfEmailListener.rst b/Documentation/Changelog/6.0/Breaking-33-RenameServiceIdOfEmailListener.rst new file mode 100644 index 0000000..7e6ed1b --- /dev/null +++ b/Documentation/Changelog/6.0/Breaking-33-RenameServiceIdOfEmailListener.rst @@ -0,0 +1,39 @@ +.. include:: ../../Includes.rst.txt + +======================================================= +Breaking: #33 - Rename Service Id of the Email Listener +======================================================= + +See `Pull Request 33 `__ + +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..383bc70 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 10.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/Tests/Functional/Configuration/EventListenerRegistrationTest.php b/Tests/Functional/Configuration/EventListenerRegistrationTest.php index 3f3fae3..f552715 100644 --- a/Tests/Functional/Configuration/EventListenerRegistrationTest.php +++ b/Tests/Functional/Configuration/EventListenerRegistrationTest.php @@ -58,7 +58,7 @@ public function sendsTheMailsOfCartAfterTheFinishedPayment(): void self::assertArrayHasKey('cart-girosolution--order--finish--email', $listeners); self::assertSame( - 'Extcode\\CartGirosolution\\EventListener\\Order\\Finish\\Email', + 'cart-girosolution--event-listener--order--finish--email', $listeners['cart-girosolution--order--finish--email']['service'] ); } From b9b4440e37fba1514670417e9fb2e7927c4cd3be Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Sat, 14 Nov 2026 16:48:16 +0100 Subject: [PATCH 20/20] [DOCS] Fix required cart version in changelog of 6.0 The version 6.x requires extcode/cart 11.x, not 10.x. Co-Authored-By: Claude Opus 5.5 --- Documentation/Changelog/6.0/Index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/Changelog/6.0/Index.rst b/Documentation/Changelog/6.0/Index.rst index 383bc70..9e483da 100644 --- a/Documentation/Changelog/6.0/Index.rst +++ b/Documentation/Changelog/6.0/Index.rst @@ -4,7 +4,7 @@ 6.0 Changes =========== -The version 6.x is a release for extcode/cart 10.x. +The version 6.x is a release for extcode/cart 11.x. **Table of contents**