diff --git a/.ahoy.yml b/.ahoy.yml index d2bb51377..d95b27bb9 100644 --- a/.ahoy.yml +++ b/.ahoy.yml @@ -97,16 +97,16 @@ commands: usage: Run all tests. cmd: | ahoy test-phpunit - ahoy test-behat - - test-behat: - usage: Run Behat tests. - cmd: docker compose exec cli behat "$@" + ahoy test-playwright test-phpunit: usage: Run PHPUnit tests. cmd: docker compose exec cli phpunit --testsuite govcms + test-playwright: + usage: Run Playwright tests. + cmd: docker compose exec -T playwright npx playwright test --config /app/tests/playwright/playwright.config.ts "$@" + test-redis: usage: Verify redis can accept connections. cmd: | @@ -118,14 +118,6 @@ commands: else echo "Redis success: Redis contains $redisKeys keys." fi - test-goss: - usage: Validate images with dgoss. - cmd: | - curl -L https://github.com/goss-org/goss/releases/latest/download/goss-linux-amd64 -o /usr/local/bin/goss - chmod +rx /usr/local/bin/goss - curl -L https://github.com/goss-org/goss/releases/latest/download/dgoss -o /usr/local/bin/dgoss - chmod +rx /usr/local/bin/dgoss - ./tests/goss/run_all.sh test-install: usage: Test a blank install. diff --git a/.docker/Dockerfile.chrome b/.docker/Dockerfile.chrome deleted file mode 100644 index 2d96c589e..000000000 --- a/.docker/Dockerfile.chrome +++ /dev/null @@ -1,3 +0,0 @@ -FROM selenium/standalone-chrome:3.141.59-oxygen - -COPY tests/behat/files /app/tests/behat/files diff --git a/.docker/Dockerfile.playwright b/.docker/Dockerfile.playwright new file mode 100644 index 000000000..d4394a11b --- /dev/null +++ b/.docker/Dockerfile.playwright @@ -0,0 +1,14 @@ +FROM mcr.microsoft.com/playwright:v1.50.0-noble + +WORKDIR /app + +# Install Playwright test runner with pinned version matching the base image. +RUN npm init -y && npm install @playwright/test@1.50.0 + +# Copy example tests and config. +COPY tests/playwright /app/tests/playwright + +EXPOSE 3000 + +# Run Playwright server, listening on all interfaces. +CMD ["npx", "playwright", "run-server", "--host", "0.0.0.0", "--port", "3000"] diff --git a/.docker/Dockerfile.test b/.docker/Dockerfile.test index b2458c7ed..0f9bf58f5 100644 --- a/.docker/Dockerfile.test +++ b/.docker/Dockerfile.test @@ -30,8 +30,11 @@ COPY .docker/images/govcms/mariadb-client.cnf /etc/my.cnf.d # Copy application files from the 'cli' stage to the current stage COPY --from=cli /app /app -# Copy PHPUnit configuration and test files -COPY --from=govcmstesting/tests:3.2.3-php8.3 /tests /app/tests +# Install dev dependencies for testing. +RUN composer install --dev + +# Copy test files. +COPY tests /app/tests # Set an environment variable for the webroot path ENV WEBROOT=web diff --git a/bake.hcl b/bake.hcl index 1c8053690..b0831414b 100644 --- a/bake.hcl +++ b/bake.hcl @@ -1,5 +1,5 @@ group "default" { - targets = ["cli", "test", "nginx", "php", "mariadb", "redis", "solr", "varnish"] + targets = ["cli", "test", "playwright", "nginx", "php", "mariadb", "redis", "solr", "varnish"] } target "cli" { @@ -37,6 +37,11 @@ target "solr" { platforms = ["linux/amd64", "linux/arm64"] } +target "playwright" { + dockerfile = ".docker/Dockerfile.playwright" + platforms = ["linux/amd64"] +} + target "varnish" { dockerfile = ".docker/Dockerfile.varnish-drupal" platforms = ["linux/amd64", "linux/arm64"] diff --git a/docker-compose.yml b/docker-compose.yml index 922b4ade5..5904bff9e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -108,11 +108,11 @@ services: - amazeeio-network - default - chrome: + playwright: build: context: . - dockerfile: $PWD/.docker/Dockerfile.chrome - image: selenium/standalone-chrome + dockerfile: $PWD/.docker/Dockerfile.playwright + image: ${DOCKERHUB_NAMESPACE:-govcms}/playwright:${GOVCMS_RELEASE_TAG:-latest} shm_size: '1gb' depends_on: - test diff --git a/tests/behat/behat.screenshot.yml b/tests/behat/behat.screenshot.yml deleted file mode 100644 index c84ea04c8..000000000 --- a/tests/behat/behat.screenshot.yml +++ /dev/null @@ -1,8 +0,0 @@ -default: - extensions: - Bex\Behat\ScreenshotExtension: - screenshot_taking_mode: failed_steps - image_drivers: - local: - screenshot_directory: '../tests/screenshots' - clear_screenshot_directory: true diff --git a/tests/behat/behat.travis.yml b/tests/behat/behat.travis.yml deleted file mode 100644 index 1545e0e81..000000000 --- a/tests/behat/behat.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -default: - autoload: - '': %paths.base%/bootstrap - suites: - default: - contexts: - - '\Drupal\DrupalExtension\Context\DrupalContext' - - '\Drupal\DrupalExtension\Context\MinkContext' - - '\Drupal\DrupalExtension\Context\MessageContext' - - '\Drupal\DrupalExtension\Context\DrushContext' - paths: - features: %paths.base%/features - extensions: - Behat\MinkExtension: - base_url: 'http://127.0.0.1:8080' - goutte: ~ - selenium2: - wd_host: 'http://localhost:4444/wd/hub' - browser: chrome - javascript_session: selenium2 - browser_name: chrome - Drupal\DrupalExtension: - blackbox: ~ - api_driver: 'drupal' - drush: - alias: 'local' - root: 'docroot' - drupal: - drupal_root: 'docroot' diff --git a/tests/behat/behat.yml b/tests/behat/behat.yml deleted file mode 100644 index 4b849ab81..000000000 --- a/tests/behat/behat.yml +++ /dev/null @@ -1,57 +0,0 @@ -default: - autoload: [ %paths.base%/bootstrap ] - gherkin: - filters: - # Allow skipping tests by tagging them with "@skipped" - tags: "~@skipped" - suites: - default: - paths: [ %paths.base%/features ] - contexts: - - FeatureContext - - Drupal\DrupalExtension\Context\DrupalContext - - Drupal\DrupalExtension\Context\MinkContext - - Drupal\DrupalExtension\Context\MarkupContext - - Drupal\DrupalExtension\Context\MessageContext - - IntegratedExperts\BehatScreenshotExtension\Context\ScreenshotContext - - extensions: - Behat\MinkExtension: - goutte: ~ - base_url: http://nginx:8080 - files_path: %paths.base%/fixtures - browser_name: chrome - selenium2: - wd_host: "http://chrome:4444/wd/hub" - capabilities: { "browser": "chrome", "version": "*", "marionette": true, "extra_capabilities": { "chromeOptions": { "w3c": false } } } - javascript_session: selenium2 - # Provides integration with Drupal APIs. - Drupal\DrupalExtension: - blackbox: ~ - api_driver: drupal - drush_driver: drush - drupal: - drupal_root: web - drush: - root: web - selectors: - message_selector: '.messages' - error_message_selector: '.messages.error' - success_message_selector: '.messages.status' - warning_message_selector: '.messages.warning' - # Allows to capture HTML and JPG screenshots (based on the driver used). - IntegratedExperts\BehatScreenshotExtension: - dir: %paths.base%/screenshots - fail: true - purge: false - # Show explicit fail information and continue the test run. - IntegratedExperts\BehatFormatProgressFail\FormatExtension: ~ - -p0: - gherkin: - filters: - tags: "@p0&&~@skipped" -p1: - gherkin: - filters: - tags: "@p1&&~@skipped" diff --git a/tests/behat/bootstrap/.gitkeep b/tests/behat/bootstrap/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/behat/bootstrap/FeatureContext.php b/tests/behat/bootstrap/FeatureContext.php deleted file mode 100644 index 684dd92f8..000000000 --- a/tests/behat/bootstrap/FeatureContext.php +++ /dev/null @@ -1,24 +0,0 @@ - - [And|*] there is agent - [When|*] I erase agent 's memory - [Then|*] there should be agent - [But|*] there should not be agent - - [Scenarios|Examples]: - | agent1 | agent2 | - | D | M | diff --git a/tests/behat/features/ui/home.feature b/tests/behat/features/ui/home.feature deleted file mode 100644 index 93afede36..000000000 --- a/tests/behat/features/ui/home.feature +++ /dev/null @@ -1,13 +0,0 @@ -Feature: Home Page - Ensure the home page is rendering correctly - - Background: - Given I am an anonymous user - When I visit "/" - - @api @javascript - Scenario: View the homepage content - And I should see "Welcome to GovCMS" - - Scenario: Check the homepage meta tag. - Then the response should contain "" diff --git a/tests/behat/features/user/user.feature b/tests/behat/features/user/user.feature deleted file mode 100644 index 106df05ca..000000000 --- a/tests/behat/features/user/user.feature +++ /dev/null @@ -1,11 +0,0 @@ -Feature: User - govCMS site user testing - - @api @javascript - Scenario: Create user - Given users: - | name | mail | - | Tim Junior | tim.junior@example.com | - And I am logged in as a user with the "Administer users" permission - When I visit "admin/people" - Then I should see the text "Tim Junior" diff --git a/tests/behat/files/autotest.jpg b/tests/behat/files/autotest.jpg deleted file mode 100644 index 3069afe9e..000000000 Binary files a/tests/behat/files/autotest.jpg and /dev/null differ diff --git a/tests/behat/files/autotest.pdf b/tests/behat/files/autotest.pdf deleted file mode 100644 index e1acc6bfb..000000000 Binary files a/tests/behat/files/autotest.pdf and /dev/null differ diff --git a/tests/behat/files/autotest.rtf b/tests/behat/files/autotest.rtf deleted file mode 100644 index d6551f394..000000000 --- a/tests/behat/files/autotest.rtf +++ /dev/null @@ -1,7 +0,0 @@ -{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf470 -{\fonttbl\f0\fswiss\fcharset0 Helvetica;} -{\colortbl;\red255\green255\blue255;} -\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0 -\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0 - -\f0\fs24 \cf0 govCMS Automated Testing!} \ No newline at end of file diff --git a/tests/goss/goss.govcms.yaml b/tests/goss/goss.govcms.yaml deleted file mode 100644 index c1818d7dc..000000000 --- a/tests/goss/goss.govcms.yaml +++ /dev/null @@ -1,43 +0,0 @@ ---- -gossfile: - sanitise.yaml: {} - -file: - /app/web/modules/contrib: - exists: true - filetype: directory - /app/web/modules/contrib/redis: - exists: true - filetype: directory - /app/web/modules/contrib/stage_file_proxy: - exists: true - filetype: directory - /home/.drush: - exists: true - filetype: directory - owner: root - group: root - mode: "0775" - /app/web/sites/all/modules/lagoon: - exists: true - filetype: directory - /app/web/sites/default/settings.php: - exists: true - filetype: file - contains: - - "Drupal settings entry point." - /usr/bin/govcms-deploy: - exists: true - mode: "0755" - /app/web/sites: - exists: true - filetype: directory - mode: "0755" - -command: - find /app/ -type f -size +1M -printf '%k\t%p\n': - exit-status: 0 - stdout: - - /app/ - stderr: [] - timeout: 10000 diff --git a/tests/goss/goss.nginx-drupal.yaml b/tests/goss/goss.nginx-drupal.yaml deleted file mode 100644 index 876c0f7b8..000000000 --- a/tests/goss/goss.nginx-drupal.yaml +++ /dev/null @@ -1,15 +0,0 @@ ---- -gossfile: - sanitise.yaml: {} - -command: - nginx -T | grep client_max_body_size | tail -1: - exit-status: 0 - stdout: - - "client_max_body_size 256M;" - -file: - /app/web/robots.txt: - exists: true - /etc/nginx/conf.d/drupal/favicon.conf: - exists: true diff --git a/tests/goss/goss.php.yaml b/tests/goss/goss.php.yaml deleted file mode 100644 index 7d9d045d6..000000000 --- a/tests/goss/goss.php.yaml +++ /dev/null @@ -1,9 +0,0 @@ ---- -gossfile: - sanitise.yaml: {} - -command: - php -r "echo ini_get('upload_max_filesize');": - exit-status: 0 - stdout: - - "256M" diff --git a/tests/goss/goss.solr.yaml b/tests/goss/goss.solr.yaml deleted file mode 100644 index ccf3984d0..000000000 --- a/tests/goss/goss.solr.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -command: - /opt/solr/bin/solr --version: - exit-status: 0 - stdout: - - "9.10.1" diff --git a/tests/goss/run_all.sh b/tests/goss/run_all.sh deleted file mode 100755 index a36336864..000000000 --- a/tests/goss/run_all.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -## -# Run all GOSS tests. -# - -TEST_DIR=${TEST_DIR:-tests/goss} - -fails=0 -for file in $TEST_DIR/goss.*.yaml; do - prefix=$TEST_DIR/goss. - service=${file/$prefix/} - service=${service/.yaml/} - echo "==> Running tests for \"$service\" service" - goss -g $file render > goss.yaml && dgoss run -i -e NGINX_FASTCGI_PASS=localhost $DOCKERHUB_NAMESPACE/$service:$GOVCMS_RELEASE_TAG || ((fails++)) - rm -Rf goss.yaml - echo "==> Finished tests for \"$service\" service" -done - -exit $fails diff --git a/tests/goss/sanitise.yaml b/tests/goss/sanitise.yaml deleted file mode 100644 index a526dff01..000000000 --- a/tests/goss/sanitise.yaml +++ /dev/null @@ -1,32 +0,0 @@ ---- -file: - /app/web/core/.env.example: - exists: false - /app/web/core/install.php: - exists: false - /app/web/core/INSTALL.txt: - exists: false - /app/web/core/INSTALL.mysql.txt: - exists: false - /app/web/core/INSTALL.pgsql.txt: - exists: false - /app/web/core/INSTALL.sqlite.txt: - exists: false - /app/web/core/CHANGELOG.txt: - exists: false - /app/web/core/COPYRIGHT.txt: - exists: false - /app/web/core/LICENSE.txt: - exists: false - /app/web/core/MAINTAINERS.txt: - exists: false - /app/web/core/UPDATE.txt: - exists: false - /app/web/web.config: - exists: false - /app/web/.editorconfig: - exists: false - /app/web/favicon.ico: - exists: false - /app/web/core/tests: - exists: true diff --git a/tests/playwright/package.json b/tests/playwright/package.json new file mode 100644 index 000000000..473304ecf --- /dev/null +++ b/tests/playwright/package.json @@ -0,0 +1,10 @@ +{ + "name": "govcms-playwright-tests", + "private": true, + "scripts": { + "test": "npx playwright test" + }, + "devDependencies": { + "@playwright/test": "^1.50.0" + } +} diff --git a/tests/playwright/playwright.config.ts b/tests/playwright/playwright.config.ts new file mode 100644 index 000000000..4bd1023fd --- /dev/null +++ b/tests/playwright/playwright.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from '@playwright/test'; + +export default defineConfig({ + testDir: './tests', + timeout: 30000, + retries: 1, + use: { + baseURL: process.env.BASE_URL || 'http://nginx:8080', + screenshot: 'only-on-failure', + trace: 'on-first-retry', + }, + reporter: [['list']], +}); diff --git a/tests/playwright/tests/homepage.spec.ts b/tests/playwright/tests/homepage.spec.ts new file mode 100644 index 000000000..54f57c9f2 --- /dev/null +++ b/tests/playwright/tests/homepage.spec.ts @@ -0,0 +1,13 @@ +import { test, expect } from '@playwright/test'; + +test.describe('Home Page', () => { + test('should render the homepage', async ({ page }) => { + await page.goto('/'); + await expect(page).toHaveTitle(/GovCMS|Drupal/); + }); + + test('should contain a welcome message', async ({ page }) => { + await page.goto('/'); + await expect(page.locator('body')).toContainText('Welcome to GovCMS'); + }); +});