Skip to main content

Authoring tests

There are 2 types of tests in Vortex:

  • PHPUnit for functional end-to-end testing of workflows.
    With help of phpunit-helpers testing library, we run tests for workflows, including container builds, database imports, and Drupal operations as if they were run by a consumer site developer.

  • Bats for unit testing of scripts in scripts/vortex.
    With help of BATS Helpers testing library, we run unit tests for shell scripts with coverage.

    info

    Heads up! Scripts are changing from Bash to PHP in 2.0 release. This will make the use of BATS obsolete. Track the progress in this issue.

Functional tests with PHPUnit

cd .vortex/tests

# Install Composer dependencies.
composer install

# Run all tests.
composer test

# Some tests require Composer and container registry tokens.
TEST_PACKAGE_TOKEN=<yourtoken> TEST_VORTEX_CONTAINER_REGISTRY_USER=<youruser> TEST_VORTEX_CONTAINER_REGISTRY_PASS=<yourpass> composer test

Functional tests rely on database fixtures - see the section below on updating test assets.

Unit tests with BATS

cd .vortex/tests

# Install npm dependencies.
npm install

# Run a single test.
bats .vortex/tests/bats/deploy.bats

Updating test assets

There are demo and test database dumps captured as files and container images.

  • Demo database dump file - demonstration of the database import capabilities from a file during a normal workflow.
  • Demo database container image - demonstration of the database import capabilities from a container image during a normal workflow.
  • Test database dump file - test of the database import capabilities from a file during the normal workflow.
  • Test database container image - test of the database import capabilities from a container image during the normal workflow.

Updating demo database dump file

  1. Run fresh build of Vortex locally:
rm .data/db.sql || true
VORTEX_PROVISION_TYPE=profile VORTEX_PROVISION_POST_OPERATIONS_SKIP=1 AHOY_CONFIRM_RESPONSE=1 ahoy build
  1. Update content and config:
ahoy cli

drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the demo site!',
'body' => [
'value' => '<p>This demo page is sourced from the Vortex database dump file to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

exit

  1. Export DB:
ahoy export-db db.demo.sql
  1. Upload db.demo.sql to the latest release as an asset and name it db_d11.demo.sql.

Updating demo database container image

  1. Run fresh build of Vortex locally:
rm .data/db.sql || true
VORTEX_PROVISION_TYPE=profile VORTEX_PROVISION_POST_OPERATIONS_SKIP=1 AHOY_CONFIRM_RESPONSE=1 ahoy build
  1. Update content and config:
ahoy cli

drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the demo site!',
'body' => [
'value' => '<p>This demo page is sourced from the Vortex database container image to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

exit

  1. Export DB:
ahoy export-db db.demo_image.sql

# Update the collation to avoid issues with MariaDB 10.5+:
sed -i '' 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' .data/db.demo_image.sql
  1. Seed the database container image:
curl -LO https://github.com/drevops/mariadb-drupal-data/releases/latest/download/seed.sh
chmod +x seed.sh
./seed.sh .data/db.demo_image.sql drevops/vortex-dev-mariadb-drupal-data-demo-11.x:latest

Updating test database dump file

  1. Run a fresh install of Vortex into a new directory and name the project Star Wars:
mkdir /tmp/star-wars
VORTEX_INSTALLER_TEMPLATE_REPO="$(pwd)" .vortex/installer/installer.php /tmp/star-wars --no-interaction
cd /tmp/star-wars
  1. Run fresh build of Vortex locally:
rm .data/db.sql || true
VORTEX_PROVISION_TYPE=profile AHOY_CONFIRM_RESPONSE=1 ahoy build
  1. Update content and config:
ahoy cli

drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the test site!',
'body' => [
'value' => '<p>This test page is sourced from the Vortex database dump file to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

exit

  1. Export DB:
ahoy export-db db.test.sql
  1. Upload db.test.sql to the latest release as an asset and name it db_d11.test.sql.

Updating test database container image

  1. Run a fresh install of Vortex into a new directory and name the project Star Wars:
mkdir /tmp/star-wars
VORTEX_INSTALLER_TEMPLATE_REPO="$(pwd)" .vortex/installer/installer.php /tmp/star-wars --no-interaction
cd /tmp/star-wars
  1. Run fresh build of Vortex locally:
rm .data/db.sql || true
VORTEX_PROVISION_TYPE=profile AHOY_CONFIRM_RESPONSE=1 ahoy build
  1. Update content and config:
ahoy cli

drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the test site!',
'body' => [
'value' => '<p>This test page is sourced from the Vortex database container image to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

exit

  1. Export DB:
ahoy export-db db.test_image.sql

# Update the collation to avoid issues with MariaDB 10.5+:
sed -i '' 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' .data/db.test_image.sql
  1. Seed the database container image:
curl -LO https://github.com/drevops/mariadb-drupal-data/releases/latest/download/seed.sh
chmod +x seed.sh
./seed.sh .data/db.test_image.sql drevops/vortex-dev-mariadb-drupal-data-test-11.x:latest
  1. Update destination container images:
docker tag drevops/vortex-dev-mariadb-drupal-data-demo-11.x:latest drevops/vortex-dev-mariadb-drupal-data-demo-destination-11.x:vortex-dev-database-ii
docker push drevops/vortex-dev-mariadb-drupal-data-demo-destination-11.x:vortex-dev-database-ii

docker tag drevops/vortex-dev-mariadb-drupal-data-demo-11.x:latest drevops/vortex-dev-mariadb-drupal-data-demo-destination-11.x:vortex-dev-didi-database-fi
docker push drevops/vortex-dev-mariadb-drupal-data-demo-destination-11.x:vortex-dev-didi-database-fi