From 84d3711241a0e309d9718153849e425ab0cb3dc8 Mon Sep 17 00:00:00 2001 From: Sally Young Date: Tue, 13 Aug 2024 11:05:08 +0100 Subject: [PATCH] Issue #638: Updates for Drupal 11 (#639) - Replace sserbin/twig-linter with vincentlanglet/twig-cs-fixer/ - sserbin/twig-linter depends on an old version of symfony/console and core is adopting this new package at some point https://www.drupal.org/project/drupal/issues/3284817 - it also has a much better extension mechanism which will help if something like Fix linting for Storybook #615 comes up again - Update Pantheon settings for Drupal 11 - Update PHPUnit configurations and tests for Drupal 11 - Fix mysterious yarn issues with DDEV --- .github/workflows/TestBinaryInstaller.yml | 11 +- .github/workflows/TestComposerLockDiff.yml | 7 +- .github/workflows/TestDDEV.yml | 6 +- .github/workflows/TestEnv.yml | 5 +- .github/workflows/TestFunctional.yml | 62 ++++++--- .github/workflows/TestGitHubActions.yml | 9 +- .github/workflows/TestMetapackages.yml | 25 ++-- .github/workflows/TestPHPUnit.yml | 21 ++- .github/workflows/TestStatic.yml | 5 +- .github/workflows/TestTugboat.yml | 6 +- .github/workflows/composer-plugin.yml | 3 +- .github/workflows/test-production-build.yml | 14 +- .tugboat/config.yml | 2 +- drainpipe-dev/composer.json | 21 +-- .../.twig-cs-fixer.dist.php} | 33 ++--- scaffold/phpunit-testtraits.xml | 35 ++++- scaffold/phpunit.xml | 36 ++++- tasks/test.yml | 28 ++-- .../tests/src/Functional/UserCreateTest.php | 5 +- .../UserPasswordResetTest.php | 2 +- .../src/Unit/PermissionAccessCheckTest.php | 126 ++++++++--------- .../tests/src/Functional/UserCreateTest.php | 5 +- .../UserPasswordResetTest.php | 2 +- .../src/Unit/PermissionAccessCheckTest.php | 127 +++++++++--------- tests/local-test.sh | 2 +- 25 files changed, 362 insertions(+), 236 deletions(-) rename drainpipe-dev/{bin/drainpipe-twig-linter => scaffold/.twig-cs-fixer.dist.php} (57%) mode change 100755 => 100644 diff --git a/.github/workflows/TestBinaryInstaller.yml b/.github/workflows/TestBinaryInstaller.yml index 7eba557e4..322c6d2cc 100644 --- a/.github/workflows/TestBinaryInstaller.yml +++ b/.github/workflows/TestBinaryInstaller.yml @@ -13,10 +13,18 @@ concurrency: jobs: Test-Binary-Installer: runs-on: ubuntu-22.04 + strategy: + matrix: + php-version: [ 8.1, 8.2, 8.3 ] + include: + - php-version: 8.1 + drupal-version: ":^10" + - php-version: 8.2 + drupal-version: ":^10" steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project${{ matrix.drupal-version }} . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -37,6 +45,7 @@ jobs: - name: Setup Project run: | ddev config --auto + ddev config --php-version ${{ matrix.php-version }} ddev start ddev composer config extra.drupal-scaffold.gitignore true ddev composer config --json extra.drupal-scaffold.allowed-packages '["lullabot/drainpipe-dev", "lullabot/drainpipe"]' diff --git a/.github/workflows/TestComposerLockDiff.yml b/.github/workflows/TestComposerLockDiff.yml index 24e6537a3..b4863a4d8 100644 --- a/.github/workflows/TestComposerLockDiff.yml +++ b/.github/workflows/TestComposerLockDiff.yml @@ -11,9 +11,12 @@ concurrency: jobs: Test-Composer-Lock-Diff: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project:10.0.9 . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project:^${{ matrix.drupal-version }} . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -77,7 +80,7 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: processed-descriptions + name: processed-descriptions-${{ matrix.drupal-version }} path: | renovate-processed.json pr-template-processed.json diff --git a/.github/workflows/TestDDEV.yml b/.github/workflows/TestDDEV.yml index db7f47a8f..1f7180130 100644 --- a/.github/workflows/TestDDEV.yml +++ b/.github/workflows/TestDDEV.yml @@ -13,9 +13,12 @@ concurrency: jobs: Test-DDEV-Install: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project:^${{ matrix.drupal-version }} . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -35,7 +38,6 @@ jobs: - name: Setup Project run: | ddev config --auto - ddev config --nodejs-version "18" ddev start ddev composer config extra.drupal-scaffold.gitignore true ddev composer config --json extra.drupal-scaffold.allowed-packages '["lullabot/drainpipe-dev", "lullabot/drainpipe"]' diff --git a/.github/workflows/TestEnv.yml b/.github/workflows/TestEnv.yml index baf1a82eb..870064912 100644 --- a/.github/workflows/TestEnv.yml +++ b/.github/workflows/TestEnv.yml @@ -11,10 +11,13 @@ concurrency: jobs: Test-Env: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Create a Drupal project run: | - composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + composer create-project drupal/recommended-project:^${{ matrix.drupal-version }} . --ignore-platform-reqs - uses: actions/checkout@v4 with: diff --git a/.github/workflows/TestFunctional.yml b/.github/workflows/TestFunctional.yml index 38a3b6347..54ffce111 100644 --- a/.github/workflows/TestFunctional.yml +++ b/.github/workflows/TestFunctional.yml @@ -13,9 +13,12 @@ concurrency: jobs: Build: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project:^${{ matrix.drupal-version }} . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -35,7 +38,8 @@ jobs: - name: Setup Project run: | ddev config --auto - ddev config --nodejs-version "18" + ddev config --nodejs-version "22" + ddev config --corepack-enable ddev start ddev composer config extra.drupal-scaffold.gitignore true ddev composer config --json extra.drupal-scaffold.allowed-packages '["lullabot/drainpipe-dev", "lullabot/drainpipe"]' @@ -64,16 +68,19 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@v4 with: - name: test-functional-build + name: test-functional-build-${{ matrix.drupal-version }} path: /tmp/drainpipe.zip Test-NPM: runs-on: ubuntu-22.04 needs: Build + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - uses: actions/download-artifact@v4 with: - name: test-functional-build + name: test-functional-build-${{ matrix.drupal-version }} - name: Restore Workspace run: | @@ -112,16 +119,19 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-npm + name: test_result-npm-${{ matrix.drupal-version }} path: test_result Test-Yarn-Classic: runs-on: ubuntu-22.04 needs: Build + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - uses: actions/download-artifact@v4 with: - name: test-functional-build + name: test-functional-build-${{ matrix.drupal-version }} - name: Restore Workspace run: | @@ -143,7 +153,9 @@ jobs: - name: Setup Nightwatch run: | - ddev yarn set version classic + ddev exec corepack disable + ddev exec npm i -g yarn@1.22.1 + ddev exec 'ln -s $(npm root -g)/yarn/bin/yarn /usr/local/bin/yarn' ddev yarn init -y ddev yarn add nightwatch nightwatch-accessibility @lullabot/nightwatch-drupal-commands lodash --dev @@ -161,16 +173,19 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-yarn-classic + name: test_result-yarn-classic-${{ matrix.drupal-version }} path: test_result Test-Yarn-3-Node-Linker: runs-on: ubuntu-22.04 needs: Build + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - uses: actions/download-artifact@v4 with: - name: test-functional-build + name: test-functional-build-${{ matrix.drupal-version }} - name: Restore Workspace run: | @@ -195,7 +210,7 @@ jobs: ddev yarn set version berry ddev yarn set version 3 ddev yarn init -y - yarn config set nodeLinker node-modules + ddev yarn config set nodeLinker node-modules ddev yarn add nightwatch nightwatch-accessibility @lullabot/nightwatch-drupal-commands lodash --dev - name: Install Drupal @@ -212,16 +227,19 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-yarn3-nl + name: test_result-yarn3-nl-${{ matrix.drupal-version }} path: test_result Test-Yarn-4-Node-Linker: runs-on: ubuntu-22.04 needs: Build + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - uses: actions/download-artifact@v4 with: - name: test-functional-build + name: test-functional-build-${{ matrix.drupal-version }} - name: Restore Workspace run: | @@ -243,12 +261,11 @@ jobs: - name: Setup Nightwatch run: | - ddev config --nodejs-version=21 ddev restart ddev yarn set version berry ddev yarn set version 4 ddev yarn init -y - yarn config set nodeLinker node-modules + ddev yarn config set nodeLinker node-modules ddev yarn add nightwatch nightwatch-accessibility @lullabot/nightwatch-drupal-commands lodash --dev - name: Install Drupal @@ -265,16 +282,19 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-yarn4-nl + name: test_result-yarn4-nl-${{ matrix.drupal-version }} path: test_result Test-Yarn-3: runs-on: ubuntu-22.04 needs: Build + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - uses: actions/download-artifact@v4 with: - name: test-functional-build + name: test-functional-build-${{ matrix.drupal-version }} - name: Restore Workspace run: | @@ -319,16 +339,19 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-yarn3 + name: test_result-yarn3-${{ matrix.drupal-version }} path: test_result Test-Yarn-4: runs-on: ubuntu-22.04 needs: Build + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - uses: actions/download-artifact@v4 with: - name: test-functional-build + name: test-functional-build-${{ matrix.drupal-version }} - name: Restore Workspace run: | @@ -350,7 +373,6 @@ jobs: - name: Setup Nightwatch run: | - ddev config --nodejs-version=21 ddev restart ddev yarn set version berry ddev yarn init -y @@ -375,5 +397,5 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-yarn4 + name: test_result-yarn4-${{ matrix.drupal-version }} path: test_result diff --git a/.github/workflows/TestGitHubActions.yml b/.github/workflows/TestGitHubActions.yml index 9e00afbc8..364056749 100644 --- a/.github/workflows/TestGitHubActions.yml +++ b/.github/workflows/TestGitHubActions.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -58,10 +58,9 @@ jobs: run: | echo "api_version: 1" >> pantheon.yml echo "web_docroot: true" >> pantheon.yml - echo "php_version: 8.1" >> pantheon.yml - echo "drush_version: 10" >> pantheon.yml + echo "php_version: 8.3" >> pantheon.yml echo "database:" >> pantheon.yml - echo " version: 10.4" >> pantheon.yml + echo " version: 10.6" >> pantheon.yml echo "enforce_https: full+subdomains" >> pantheon.yml echo "build_step: false" >> pantheon.yml @@ -78,7 +77,7 @@ jobs: echo "\$settings['container_yamls'][] = __DIR__ . '/services.yml';" >> web/sites/default/settings.php echo "include __DIR__ . \"/settings.pantheon.php\";" >> web/sites/default/settings.php echo "\$settings['config_sync_directory'] = '../config';" >> web/sites/default/settings.php - curl -o web/sites/default/settings.pantheon.php https://raw.githubusercontent.com/pantheon-systems/drops-8/default/sites/default/settings.pantheon.php + curl -o web/sites/default/settings.pantheon.php https://raw.githubusercontent.com/pantheon-systems/drupal-integrations/11.x/assets/settings.pantheon.php - name: Snapshot Project env: diff --git a/.github/workflows/TestMetapackages.yml b/.github/workflows/TestMetapackages.yml index 4bbd57d78..dedde9f90 100644 --- a/.github/workflows/TestMetapackages.yml +++ b/.github/workflows/TestMetapackages.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -35,7 +35,8 @@ jobs: - name: Setup Project run: | ddev config --auto - ddev config --nodejs-version "18" + ddev config --nodejs-version "22" + ddev config --corepack-enable ddev start ddev composer config extra.drupal-scaffold.gitignore true ddev composer config --json extra.drupal-scaffold.allowed-packages '["lullabot/drainpipe-dev", "lullabot/drainpipe"]' @@ -126,9 +127,11 @@ jobs: - name: Setup Sass run: | - ddev yarn set version classic - ddev yarn init -y - ddev yarn add file:./drainpipe/metapackages/sass --dev + ddev exec corepack disable + ddev exec npm i -g yarn@1.22.1 + ddev exec 'ln -s $(npm root -g)/yarn/bin/yarn /usr/local/bin/yarn' + ddev exec yarn init -y + ddev exec yarn add file:./drainpipe/metapackages/sass --dev - name: Compile Sass run: ddev task sass @@ -197,7 +200,6 @@ jobs: - name: Setup Sass run: | - ddev config --nodejs-version=21 ddev restart ddev yarn set version berry ddev yarn set version 4 @@ -271,10 +273,12 @@ jobs: - name: Setup Sass run: | - ddev yarn set version classic - ddev yarn init -y - ddev yarn add focus-trap@^6.7.3 - ddev yarn add file:./drainpipe/metapackages/javascript --dev + ddev exec corepack disable + ddev exec npm i -g yarn@1.22.1 + ddev exec 'ln -s $(npm root -g)/yarn/bin/yarn /usr/local/bin/yarn' + ddev exec yarn init -y + ddev exec yarn add focus-trap@^6.7.3 + ddev exec yarn add file:./drainpipe/metapackages/javascript --dev - name: Compile JavaScript run: ddev task javascript @@ -344,7 +348,6 @@ jobs: - name: Setup Sass run: | - ddev config --nodejs-version=21 ddev restart ddev yarn set version berry ddev yarn set version 4 diff --git a/.github/workflows/TestPHPUnit.yml b/.github/workflows/TestPHPUnit.yml index 3a1d18585..1e9ec340b 100644 --- a/.github/workflows/TestPHPUnit.yml +++ b/.github/workflows/TestPHPUnit.yml @@ -13,12 +13,15 @@ concurrency: jobs: Test-PHPUnit-Functional: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Install xmllint run: sudo apt-get update && sudo apt-get install -y libxml2-utils - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project:^${{ matrix.drupal-version }} . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -71,18 +74,21 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-phpunit-functional + name: test_result-phpunit-functional-${{ matrix.drupal-version }} path: test_result - name: Confirm All PHPUnit Functional Tests were run uses: GuillaumeFalourd/assert-command-line-output@v2.3 with: command_line: xmllint --xpath 'string(//testsuites/testsuite/@tests)' test_result/phpunit-functional.xml - contains: 18 + contains: 6 expected_result: PASSED Test-PHPUnit-Functional-DTT: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Install xmllint run: sudo apt-get update && sudo apt-get install -y libxml2-utils @@ -140,18 +146,21 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-phpunit-dtt + name: test_result-phpunit-dtt-${{ matrix.drupal-version }} path: test_result - name: Confirm All PHPUnit Functional Tests were run uses: GuillaumeFalourd/assert-command-line-output@v2 with: command_line: xmllint --xpath 'string(//testsuites/testsuite/@tests)' test_result/phpunit-functional.xml - contains: 21 + contains: 9 expected_result: PASSED Test-PHPUnit-Static: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Install xmllint run: sudo apt-get update && sudo apt-get install -y libxml2-utils @@ -205,7 +214,7 @@ jobs: if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: test_result-phpunit-static + name: test_result-phpunit-static-${{ matrix.drupal-version }} path: test_result - name: Confirm All PHPUnit Functional Tests were run diff --git a/.github/workflows/TestStatic.yml b/.github/workflows/TestStatic.yml index 720eacf6d..9c10fa1f0 100644 --- a/.github/workflows/TestStatic.yml +++ b/.github/workflows/TestStatic.yml @@ -13,9 +13,12 @@ concurrency: jobs: Test-Static: runs-on: ubuntu-22.04 + strategy: + matrix: + drupal-version: [ 10, 11 ] steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project:^${{ matrix.drupal-version }} . --ignore-platform-reqs - uses: actions/checkout@v4 with: diff --git a/.github/workflows/TestTugboat.yml b/.github/workflows/TestTugboat.yml index 0022b72ed..d3d7c5dca 100644 --- a/.github/workflows/TestTugboat.yml +++ b/.github/workflows/TestTugboat.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Create a Drupal project - run: composer create-project drupal/recommended-project . --ignore-platform-req=ext-gd + run: composer create-project drupal/recommended-project . --ignore-platform-reqs - uses: actions/checkout@v4 with: @@ -34,7 +34,7 @@ jobs: - name: Setup Project run: | ddev config --auto - ddev config --php-version "8.1" + ddev config --php-version "8.3" ddev config --nodejs-version "18" ddev get ddev/ddev-redis --version v1.2.0 ddev get ddev/ddev-elasticsearch --version v0.3.2 @@ -119,7 +119,7 @@ jobs: - name: Setup Project run: | ddev config --auto - ddev config --php-version "8.1" + ddev config --php-version "8.3" ddev config --nodejs-version "16" ddev restart ddev composer config extra.drupal-scaffold.gitignore true diff --git a/.github/workflows/composer-plugin.yml b/.github/workflows/composer-plugin.yml index 9b3c17a02..04820bf51 100644 --- a/.github/workflows/composer-plugin.yml +++ b/.github/workflows/composer-plugin.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - php-version: [8.1, 8.2, 8.3] + php-version: [ 8.1, 8.2, 8.3 ] steps: - uses: actions/checkout@v4 @@ -36,4 +36,5 @@ jobs: restore-keys: ${{ runner.os }}-composer- - run: composer install + - run: ./vendor/bin/phpunit diff --git a/.github/workflows/test-production-build.yml b/.github/workflows/test-production-build.yml index cd37bdb32..c5c9408b1 100644 --- a/.github/workflows/test-production-build.yml +++ b/.github/workflows/test-production-build.yml @@ -6,13 +6,21 @@ on: pull_request: types: [opened, synchronize, reopened] +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: Test-Production-Build: runs-on: ubuntu-22.04 strategy: matrix: - php-version: [8.1, 8.2, 8.3] - + php-version: [ 8.1, 8.2, 8.3 ] + include: + - php-version: 8.1 + drupal-version: ":^10" + - php-version: 8.2 + drupal-version: ":^10" steps: - uses: actions/checkout@v4 @@ -37,7 +45,7 @@ jobs: - name: Install Drupal run: | cd ../ - composer create-project drupal/recommended-project drupal --ignore-platform-req=ext-gd + composer create-project drupal/recommended-project${{ matrix.drupal-version }} drupal --ignore-platform-reqs cd drupal cp ${GITHUB_WORKSPACE}/tests/fixtures.drainpipe-test-build/Taskfile.yml . composer config extra.drupal-scaffold.gitignore true diff --git a/.tugboat/config.yml b/.tugboat/config.yml index 656da9da7..b6c05141f 100644 --- a/.tugboat/config.yml +++ b/.tugboat/config.yml @@ -11,7 +11,7 @@ services: php: http: false - image: tugboatqa/php-nginx:8.1-fpm + image: tugboatqa/php-nginx:8.3-fpm default: true depends: diff --git a/drainpipe-dev/composer.json b/drainpipe-dev/composer.json index ba06a57a0..edaeb35a1 100644 --- a/drainpipe-dev/composer.json +++ b/drainpipe-dev/composer.json @@ -13,20 +13,20 @@ "php": "^8.1", "ext-json": "*", "composer-plugin-api": "^2.0", - "phpunit/phpunit": "^9.6.20", - "sserbin/twig-linter": "^3.1.0", - "mikey179/vfsstream": "^1.6.11", - "mockery/mockery": "^1.6.12", "behat/mink": "^1.11.0", - "symfony/phpunit-bridge": "^6|^7", + "behat/mink-browserkit-driver": "^2.2.0", + "drupal/coder": "^8.3.24", "lullabot/drainpipe": "*", "mglaman/phpstan-drupal": "^1.2.11", + "mikey179/vfsstream": "^1.6.11", + "mockery/mockery": "^1.6.12", + "phpspec/prophecy-phpunit": "^2", + "phpstan/phpstan-deprecation-rules": "^1.2.0", + "phpunit/phpunit": "^9|^10", + "symfony/phpunit-bridge": "^6|^7", "symfony/yaml": "^6|^7", - "drupal/coder": "^8.3.24", - "behat/mink-browserkit-driver": "^2.2.0", "tijsverkoyen/convert-to-junit-xml": "^1.11.0", - "phpstan/phpstan-deprecation-rules": "^1.2.0", - "phpspec/prophecy-phpunit": "^2" + "vincentlanglet/twig-cs-fixer": "^3.0.0" }, "require-dev": { "composer/composer": "^2.7.7" @@ -49,7 +49,8 @@ "[project-root]/.ddev/docker-compose.selenium.yaml": "scaffold/nightwatch/docker-compose.selenium.yaml", "[project-root]/test/nightwatch/example.nightwatch.js": "scaffold/nightwatch/example.nightwatch.js", "[project-root]/phpcs.xml.dist": "scaffold/phpcs.xml.dist", - "[project-root]/phpstan.neon.dist": "scaffold/phpstan.neon.dist" + "[project-root]/phpstan.neon.dist": "scaffold/phpstan.neon.dist", + "[project-root]/.twig-cs-fixer.dist.php": "scaffold/.twig-cs-fixer.dist.php" } } }, diff --git a/drainpipe-dev/bin/drainpipe-twig-linter b/drainpipe-dev/scaffold/.twig-cs-fixer.dist.php old mode 100755 new mode 100644 similarity index 57% rename from drainpipe-dev/bin/drainpipe-twig-linter rename to drainpipe-dev/scaffold/.twig-cs-fixer.dist.php index 607934fa8..f4a8ad90c --- a/drainpipe-dev/bin/drainpipe-twig-linter +++ b/drainpipe-dev/scaffold/.twig-cs-fixer.dist.php @@ -1,4 +1,3 @@ -#!/usr/bin/env php addStandard(new TwigCsFixer\Standard\TwigCsFixer()); + +$config = new TwigCsFixer\Config\Config(); +$config->setRuleset($ruleset); +$config->addTwigExtension(new TwigExtension($renderer, $urlGenerator, $themeManager, $dateFormatter, $fileUrlGenerator)); + if (class_exists('\TwigStorybook\Twig\TwigExtension')) { $composer_json = json_decode(file_get_contents(__DIR__ . '/../../../../composer.json'), true); if (json_last_error()) { @@ -43,14 +43,7 @@ } $web_root = $composer_json['extra']['drupal-scaffold']['locations']['web-root']; - $twig->addExtension(new \TwigStorybook\Twig\TwigExtension(new \TwigStorybook\Service\StoryCollector(), '/../../../../' . $web_root)); + $config->addExtension(new \TwigStorybook\Twig\TwigExtension(new \TwigStorybook\Service\StoryCollector(), '/../../../../' . $web_root)); } -$twig->addExtension(new TwigExtension($renderer, $urlGenerator, $themeManager, $dateFormatter, $fileUrlGenerator)); - -$lintCommand = new LintCommand($twig); - -$app = new Application('twig-linter', (string) Versions::getVersion('sserbin/twig-linter')); -$app->add($lintCommand); -$app->setDefaultCommand('lint'); -$app->run(); +return $config; diff --git a/scaffold/phpunit-testtraits.xml b/scaffold/phpunit-testtraits.xml index 85efdfd8a..291acf8f3 100644 --- a/scaffold/phpunit-testtraits.xml +++ b/scaffold/phpunit-testtraits.xml @@ -1,12 +1,18 @@ + colors="true" + beStrictAboutTestsThatDoNotTestAnything="true" + beStrictAboutOutputDuringTests="true" + beStrictAboutChangesToGlobalState="true" + failOnWarning="true" + displayDetailsOnTestsThatTriggerErrors="true" + displayDetailsOnTestsThatTriggerWarnings="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + cacheResult="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + cacheDirectory=".phpunit.cache"> @@ -31,6 +37,25 @@ + + + + + + + + + ../../../../web/modules/custom/*/tests/src/Unit diff --git a/scaffold/phpunit.xml b/scaffold/phpunit.xml index 5f3f9d1d2..da44e35c8 100644 --- a/scaffold/phpunit.xml +++ b/scaffold/phpunit.xml @@ -1,12 +1,18 @@ + colors="true" + beStrictAboutTestsThatDoNotTestAnything="true" + beStrictAboutOutputDuringTests="true" + beStrictAboutChangesToGlobalState="true" + failOnWarning="true" + displayDetailsOnTestsThatTriggerErrors="true" + displayDetailsOnTestsThatTriggerWarnings="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + cacheResult="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + cacheDirectory=".phpunit.cache"> @@ -28,8 +34,28 @@ + + + + + + + + + + ../../../../web/modules/custom/*/tests/src/Unit ../../../../web/modules/custom/*/*/tests/src/Unit ../../../../web/modules/custom/*/modules/*/tests/src/Unit diff --git a/tasks/test.yml b/tasks/test.yml index c0cff87aa..d11aeadb6 100644 --- a/tasks/test.yml +++ b/tasks/test.yml @@ -54,7 +54,11 @@ tasks: - | DIRS_ARR=({{.TWIG_DIRS}}) for DIR in "${DIRS_ARR[@]}"; do - ./vendor/bin/drainpipe-twig-linter lint $DIR + if [ "{{.format}}" == "junit" ]; then + ./vendor/bin/twig-cs-fixer lint $DIR --format junit + else + ./vendor/bin/twig-cs-fixer lint $DIR + fi done - | if [ -f ".prettierrc.json" ] && [ -f "yarn.lock" ]; then @@ -110,11 +114,10 @@ tasks: CONFIG="$(pwd)/vendor/lullabot/drainpipe/scaffold/phpunit-testtraits.xml" fi if [ "{{.format}}" == "junit" ]; then - mkdir -p test_result - ./vendor/bin/phpunit --testsuite=unit -c $CONFIG --log-junit $(pwd)/test_result/phpunit.xml - else - ./vendor/bin/phpunit -c $CONFIG --testsuite=unit + mkdir -p test_result/phpunit + CONFIG="$CONFIG --log-junit $(pwd)/test_result/phpunit.xml" fi + ./vendor/bin/phpunit -c $CONFIG --testsuite=unit phpunit:functional: desc: Runs PHPUnit functional tests cmds: @@ -124,10 +127,14 @@ tasks: CONFIG="$(pwd)/vendor/lullabot/drainpipe/scaffold/phpunit-testtraits.xml" fi if [ "{{.format}}" == "junit" ]; then - mkdir -p test_result - ./vendor/bin/phpunit --exclude-group=unit -c $CONFIG --log-junit $(pwd)/test_result/phpunit-functional.xml + mkdir -p test_result/phpunit + CONFIG="$CONFIG --log-junit $(pwd)/test_result/phpunit-functional.xml" + fi + PHPUNIT_VERSION=$(./vendor/bin/phpunit --version | grep -Po 'PHPUnit [0-9]+\.' | grep -Po '[0-9]+') + if [ "$PHPUNIT_VERSION" == "9" ]; then + ./vendor/bin/phpunit -c $CONFIG --testsuite=kernel,functional,functional-javascript,existing-site,existing-site-javascript else - ./vendor/bin/phpunit -c $CONFIG --exclude-group=unit + ./vendor/bin/phpunit -c $CONFIG --exclude-testsuite=unit fi phpcs: desc: Runs PHPCS with Drupal Coding Standards @@ -161,6 +168,11 @@ tasks: elif [ -f ".stylelintrc.json" ] && [ -f "package-lock.json" ]; then npm run stylelint "**/*.{css,scss,sass}" --fix fi + - | + DIRS_ARR=({{.TWIG_DIRS}}) + for DIR in "${DIRS_ARR[@]}"; do + ./vendor/bin/twig-cs-fixer lint --fix $DIR + done nightwatch:check: #desc: Verifies Nightwatch is setup correctly cmds: diff --git a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Functional/UserCreateTest.php b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Functional/UserCreateTest.php index 4058f0df1..1188ccc72 100644 --- a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Functional/UserCreateTest.php +++ b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Functional/UserCreateTest.php @@ -37,9 +37,10 @@ class UserCreateTest extends BrowserTestBase { public function testUserAdd() { $user = $this->drupalCreateUser(['administer users']); $this->drupalLogin($user); + $request_time = \Drupal::time()->getRequestTime(); - $this->assertEquals(REQUEST_TIME, $user->getCreatedTime(), 'Creating a user sets default "created" timestamp.'); - $this->assertEquals(REQUEST_TIME, $user->getChangedTime(), 'Creating a user sets default "changed" timestamp.'); + $this->assertEquals($request_time, $user->getCreatedTime(), 'Creating a user sets default "created" timestamp.'); + $this->assertEquals($request_time, $user->getChangedTime(), 'Creating a user sets default "changed" timestamp.'); // Create a field. $field_name = 'test_field'; diff --git a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php index ff6bdafe7..118bc7f42 100644 --- a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php +++ b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php @@ -65,7 +65,7 @@ protected function setUp(): void { // Set the last login time that is used to generate the one-time link so // that it is definitely over a second ago. - $account->login = REQUEST_TIME - mt_rand(10, 100000); + $account->login = \Drupal::time()->getRequestTime() - mt_rand(10, 100000); Database::getConnection()->update('users_field_data') ->fields(['login' => $account->getLastLoginTime()]) ->condition('uid', $account->id()) diff --git a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php index 10144022d..f59a0b479 100644 --- a/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php +++ b/tests/fixtures/phpunit/testmodule/modules/testsubmodule/tests/src/Unit/PermissionAccessCheckTest.php @@ -1,5 +1,7 @@ container = new ContainerBuilder(); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); - $cache_contexts_manager->reveal(); - $this->container->set('cache_contexts_manager', $cache_contexts_manager); - \Drupal::setContainer($this->container); + $this->container = new ContainerBuilder(); + $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); + $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); + $cache_contexts_manager->reveal(); + $this->container->set('cache_contexts_manager', $cache_contexts_manager); + \Drupal::setContainer($this->container); - $this->accessCheck = new PermissionAccessCheck(); - } + $this->accessCheck = new PermissionAccessCheck(); + } - /** - * Provides data for the testAccess method. - * - * @return array - */ - public function providerTestAccess() { - return [ - [[], FALSE], - [['_permission' => 'allowed'], TRUE, ['user.permissions']], - [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], - [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], - [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], - [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], - ]; - } + /** + * Provides data for the testAccess method. + * + * @return array + */ + public static function providerTestAccess() { + return [ + [[], FALSE], + [['_permission' => 'allowed'], TRUE, ['user.permissions']], + [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], + [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], + [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], + [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], + ]; + } - /** - * Tests the access check method. - * - * @dataProvider providerTestAccess - * @covers ::access - */ - public function testAccess($requirements, $access, array $contexts = [], $message = '') { - $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); - if (!empty($message)) { - $access_result->setReason($message); - } - $user = $this->createMock('Drupal\Core\Session\AccountInterface'); - $user->expects($this->any()) - ->method('hasPermission') - ->willReturnMap([ - ['allowed', TRUE], - ['denied', FALSE], - ['other', FALSE], - ]); - $route = new Route('', [], $requirements); - - $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + /** + * Tests the access check method. + * + * @dataProvider providerTestAccess + * @covers ::access + */ + public function testAccess($requirements, $access, array $contexts = [], $message = ''): void { + $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); + if (!empty($message)) { + $access_result->setReason($message); } + $user = $this->createMock('Drupal\Core\Session\AccountInterface'); + $user->expects($this->any()) + ->method('hasPermission') + ->willReturnMap([ + ['allowed', TRUE], + ['denied', FALSE], + ['other', FALSE], + ]); + $route = new Route('', [], $requirements); + + $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + } } diff --git a/tests/fixtures/phpunit/testmodule/tests/src/Functional/UserCreateTest.php b/tests/fixtures/phpunit/testmodule/tests/src/Functional/UserCreateTest.php index e354c7227..35e8e2f53 100644 --- a/tests/fixtures/phpunit/testmodule/tests/src/Functional/UserCreateTest.php +++ b/tests/fixtures/phpunit/testmodule/tests/src/Functional/UserCreateTest.php @@ -37,9 +37,10 @@ class UserCreateTest extends BrowserTestBase { public function testUserAdd() { $user = $this->drupalCreateUser(['administer users']); $this->drupalLogin($user); + $request_time = \Drupal::time()->getRequestTime(); - $this->assertEquals(REQUEST_TIME, $user->getCreatedTime(), 'Creating a user sets default "created" timestamp.'); - $this->assertEquals(REQUEST_TIME, $user->getChangedTime(), 'Creating a user sets default "changed" timestamp.'); + $this->assertEquals($request_time, $user->getCreatedTime(), 'Creating a user sets default "created" timestamp.'); + $this->assertEquals($request_time, $user->getChangedTime(), 'Creating a user sets default "changed" timestamp.'); // Create a field. $field_name = 'test_field'; diff --git a/tests/fixtures/phpunit/testmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php b/tests/fixtures/phpunit/testmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php index ed6f04620..fbac24fbb 100644 --- a/tests/fixtures/phpunit/testmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php +++ b/tests/fixtures/phpunit/testmodule/tests/src/FunctionalJavascript/UserPasswordResetTest.php @@ -65,7 +65,7 @@ protected function setUp(): void { // Set the last login time that is used to generate the one-time link so // that it is definitely over a second ago. - $account->login = REQUEST_TIME - mt_rand(10, 100000); + $account->login = \Drupal::time()->getRequestTime() - mt_rand(10, 100000); Database::getConnection()->update('users_field_data') ->fields(['login' => $account->getLastLoginTime()]) ->condition('uid', $account->id()) diff --git a/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php b/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php index 5842bcc06..c3d670dc4 100644 --- a/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php +++ b/tests/fixtures/phpunit/testmodule/tests/src/Unit/PermissionAccessCheckTest.php @@ -1,5 +1,8 @@ container = new ContainerBuilder(); - $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); - $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); - $cache_contexts_manager->reveal(); - $this->container->set('cache_contexts_manager', $cache_contexts_manager); - \Drupal::setContainer($this->container); + $this->container = new ContainerBuilder(); + $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); + $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); + $cache_contexts_manager->reveal(); + $this->container->set('cache_contexts_manager', $cache_contexts_manager); + \Drupal::setContainer($this->container); - $this->accessCheck = new PermissionAccessCheck(); - } + $this->accessCheck = new PermissionAccessCheck(); + } - /** - * Provides data for the testAccess method. - * - * @return array - */ - public function providerTestAccess() { - return [ - [[], FALSE], - [['_permission' => 'allowed'], TRUE, ['user.permissions']], - [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], - [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], - [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], - [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], - ]; - } + /** + * Provides data for the testAccess method. + * + * @return array + */ + public static function providerTestAccess() { + return [ + [[], FALSE], + [['_permission' => 'allowed'], TRUE, ['user.permissions']], + [['_permission' => 'denied'], FALSE, ['user.permissions'], "The 'denied' permission is required."], + [['_permission' => 'allowed+denied'], TRUE, ['user.permissions']], + [['_permission' => 'allowed+denied+other'], TRUE, ['user.permissions']], + [['_permission' => 'allowed,denied'], FALSE, ['user.permissions'], "The following permissions are required: 'allowed' AND 'denied'."], + ]; + } - /** - * Tests the access check method. - * - * @dataProvider providerTestAccess - * @covers ::access - */ - public function testAccess($requirements, $access, array $contexts = [], $message = '') { - $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); - if (!empty($message)) { - $access_result->setReason($message); - } - $user = $this->createMock('Drupal\Core\Session\AccountInterface'); - $user->expects($this->any()) - ->method('hasPermission') - ->willReturnMap([ - ['allowed', TRUE], - ['denied', FALSE], - ['other', FALSE], - ]); - $route = new Route('', [], $requirements); - - $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + /** + * Tests the access check method. + * + * @dataProvider providerTestAccess + * @covers ::access + */ + public function testAccess($requirements, $access, array $contexts = [], $message = ''): void { + $access_result = AccessResult::allowedIf($access)->addCacheContexts($contexts); + if (!empty($message)) { + $access_result->setReason($message); } + $user = $this->createMock('Drupal\Core\Session\AccountInterface'); + $user->expects($this->any()) + ->method('hasPermission') + ->willReturnMap([ + ['allowed', TRUE], + ['denied', FALSE], + ['other', FALSE], + ]); + $route = new Route('', [], $requirements); + + $this->assertEquals($access_result, $this->accessCheck->access($route, $user)); + } } diff --git a/tests/local-test.sh b/tests/local-test.sh index 3fe77356b..7604fa698 100755 --- a/tests/local-test.sh +++ b/tests/local-test.sh @@ -2,7 +2,7 @@ set -eux # Helper script to setup a local test of Drainpipe # Copy this to the same directory level that your drainpipe directory is in -composer create-project drupal/recommended-project drainpipe-test --ignore-platform-req=ext-gd +composer create-project drupal/recommended-project drainpipe-test --ignore-platform-reqs cd drainpipe-test cp -R ../drainpipe .