From 9cdb94d0610ae2bc749639200f99c1d16a5f141d Mon Sep 17 00:00:00 2001 From: Michael Strelan Date: Wed, 10 Jan 2024 09:31:15 +1000 Subject: [PATCH 1/6] Add phpunit tests --- tests/phpunit.bats | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/phpunit.bats diff --git a/tests/phpunit.bats b/tests/phpunit.bats new file mode 100644 index 0000000..8783ab6 --- /dev/null +++ b/tests/phpunit.bats @@ -0,0 +1,36 @@ +DRUPAL_VERSION="${DRUPAL_VERSION:-9.4}" + +setup() { + DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )" + cd "$DIR/../" || exit + BREW_PREFIX="$(brew --prefix)" + load "${BREW_PREFIX}/lib/bats-assert/load.bash" +} + +dce() { + docker compose exec -T php-cli "$@" +} + +phpunit() { + dce phpunit "$@" +} + +@test "Drupal unit test" { + run phpunit app/core/tests/Drupal/Tests/Core/DrupalTest.php + assert_output --partial "OK" +} + +@test "Drupal kernel test" { + run phpunit app/core/tests/Drupal/KernelTests/KernelTestBaseTest.php + assert_output --partial "OK" +} + +@test "Drupal functional test" { + run phpunit app/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php + assert_output --partial "OK" +} + +@test "Drupal functional javascript test" { + run phpunit app/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php + assert_output --partial "OK" +} \ No newline at end of file From 542250bb00643de79ab01513b8bb488c93019150 Mon Sep 17 00:00:00 2001 From: Michael Strelan Date: Wed, 10 Jan 2024 09:40:02 +1000 Subject: [PATCH 2/6] Test with drupalci/chromedriver --- docker-compose.yml | 2 +- phpunit.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c8194c9..fd66e13 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,5 +49,5 @@ services: network_mode: service:nginx selenium: - image: ${SELENIUM_IMAGE:-selenium/standalone-chrome:111.0} + image: ${SELENIUM_IMAGE:-drupalci/chromedriver:production} network_mode: service:nginx diff --git a/phpunit.xml b/phpunit.xml index 9b60293..9ac2f68 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,7 +18,7 @@ - + From e078b19f392f2e180d4548cd29838701b7399c4c Mon Sep 17 00:00:00 2001 From: Michael Strelan Date: Wed, 10 Jan 2024 10:14:59 +1000 Subject: [PATCH 3/6] Filter test cases --- tests/phpunit.bats | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/phpunit.bats b/tests/phpunit.bats index 8783ab6..44ac8a3 100644 --- a/tests/phpunit.bats +++ b/tests/phpunit.bats @@ -16,21 +16,23 @@ phpunit() { } @test "Drupal unit test" { - run phpunit app/core/tests/Drupal/Tests/Core/DrupalTest.php - assert_output --partial "OK" + run phpunit app/core/tests/Drupal/Tests/UnitTestCaseTest.php + assert_success } @test "Drupal kernel test" { - run phpunit app/core/tests/Drupal/KernelTests/KernelTestBaseTest.php - assert_output --partial "OK" + run phpunit app/core/tests/Drupal/KernelTests/KernelTestBaseTest.php --filter=testBootEnvironment + assert_success } @test "Drupal functional test" { - run phpunit app/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php - assert_output --partial "OK" + run phpunit app/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php --filter=testGoTo + assert_success + assert_output --partial "HTML output was generated" } @test "Drupal functional javascript test" { - run phpunit app/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php - assert_output --partial "OK" + run phpunit app/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php --filter=testJavascript + assert_success + assert_output --partial "HTML output was generated" } \ No newline at end of file From 90c142ea985e97bbbd2d815e49d99555339a341a Mon Sep 17 00:00:00 2001 From: Michael Strelan Date: Wed, 10 Jan 2024 11:01:23 +1000 Subject: [PATCH 4/6] Matrix test --- .github/workflows/tests.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2c3c7e7..f172eba 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,3 +43,37 @@ jobs: run: | cd drupal-contrib bats tests + + browser-tests: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + image: ['drupalci/chromedriver:production', 'selenium/standalone-chrome:111.0', 'selenium/standalone-firefox:111.0'] + + steps: + - name: Create project + run: | + composer create-project --ignore-platform-reqs mstrelan/drupal-contrib:dev-${{ github.ref_name }} + + - name: Initialise environment + run: | + cd drupal-contrib + make 11.x + + - name: Setup homebrew + uses: Homebrew/actions/setup-homebrew@master + + - name: Setup bats + run: | + brew tap kaos/shell + brew install bats-support bats-assert bats-file + + - name: Run tests + env: + SELENIUM_IMAGE: ${{ matrix.image }} + MINK_DRIVER_ARGS_WEBDRIVER: ${{ matrix.drupal_version == 'drupalci/chromedriver:production' && '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://127.0.0.1:9515"]' || matrix.drupal_version == 'selenium/standalone-chrome:111.0' && '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://127.0.0.1:4444/wd/hub"]' || matrix.drupal_version == 'selenium/standalone-firefox:111.0' && '["firefox", {"browserName":"firefox"}, "http://127.0.0.1:4444/wd/hub"]'}} + run: | + cd drupal-contrib + bats tests/phpunit.bats \ No newline at end of file From 90392ca137675dccb90cd53d8f3567be84816480 Mon Sep 17 00:00:00 2001 From: Michael Strelan Date: Wed, 10 Jan 2024 11:08:29 +1000 Subject: [PATCH 5/6] Fix env --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f172eba..c790f7f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,6 +58,9 @@ jobs: composer create-project --ignore-platform-reqs mstrelan/drupal-contrib:dev-${{ github.ref_name }} - name: Initialise environment + env: + SELENIUM_IMAGE: ${{ matrix.image }} + MINK_DRIVER_ARGS_WEBDRIVER: ${{ matrix.image == 'drupalci/chromedriver:production' && '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://127.0.0.1:9515"]' || matrix.image == 'selenium/standalone-chrome:111.0' && '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://127.0.0.1:4444/wd/hub"]' || matrix.image == 'selenium/standalone-firefox:111.0' && '["firefox", {"browserName":"firefox"}, "http://127.0.0.1:4444/wd/hub"]' || ''}} run: | cd drupal-contrib make 11.x @@ -71,9 +74,6 @@ jobs: brew install bats-support bats-assert bats-file - name: Run tests - env: - SELENIUM_IMAGE: ${{ matrix.image }} - MINK_DRIVER_ARGS_WEBDRIVER: ${{ matrix.drupal_version == 'drupalci/chromedriver:production' && '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://127.0.0.1:9515"]' || matrix.drupal_version == 'selenium/standalone-chrome:111.0' && '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--headless", "--disable-gpu", "--no-sandbox", "--disable-dev-shm-usage"]}}, "http://127.0.0.1:4444/wd/hub"]' || matrix.drupal_version == 'selenium/standalone-firefox:111.0' && '["firefox", {"browserName":"firefox"}, "http://127.0.0.1:4444/wd/hub"]'}} run: | cd drupal-contrib bats tests/phpunit.bats \ No newline at end of file From 069eefbcf748f2a297348d41bb3fcfe8f714620c Mon Sep 17 00:00:00 2001 From: Michael Strelan Date: Wed, 10 Jan 2024 11:21:28 +1000 Subject: [PATCH 6/6] Give javascript test more chances to fail --- tests/phpunit.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit.bats b/tests/phpunit.bats index 44ac8a3..16e5610 100644 --- a/tests/phpunit.bats +++ b/tests/phpunit.bats @@ -32,7 +32,7 @@ phpunit() { } @test "Drupal functional javascript test" { - run phpunit app/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php --filter=testJavascript + run phpunit app/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php assert_success assert_output --partial "HTML output was generated" } \ No newline at end of file