From 90eeb91e7bc4b31096fca8bac4fb46cafad9ed02 Mon Sep 17 00:00:00 2001 From: Randy Fay Date: Thu, 2 May 2024 11:45:23 -0600 Subject: [PATCH] feat: Allow installing and testing with all database types --- README.md | 163 +++++++++++++++------------- config.core-dev.yaml | 31 ++++++ core-dev/.env | 2 +- core-dev/phpunit-chrome.xml | 205 +++++++++++++++++------------------ core-dev/phpunit-firefox.xml | 205 +++++++++++++++++------------------ install.yaml | 6 +- 6 files changed, 327 insertions(+), 285 deletions(-) create mode 100644 config.core-dev.yaml diff --git a/README.md b/README.md index 2721e7e..bfbded9 100644 --- a/README.md +++ b/README.md @@ -1,73 +1,90 @@ -# ddev-core-dev - -This is a DDEV addon for doing Drupal core development. - -We're in #ddev-for-core-dev on [Drupal Slack](https://www.drupal.org/community/contributor-guide/reference-information/talk/tools/slack) (but please try and keep work and feature requests in Issues where it's visible to all 🙏) - -``` -git clone https://git.drupalcode.org/project/drupal.git drupal -cd drupal -ddev config --omit-containers=db --disable-settings-management -ddev start -ddev get justafish/ddev-drupal-core-dev -ddev restart -ddev composer install - -# See included commands -ddev drupal list - -# Install drupal -ddev drupal install - -# Run PHPUnit tests -ddev phpunit core/modules/sdc - -# Run Nightwatch tests (currently only runs on Chrome) -ddev nightwatch --tag core -``` - -## Nightwatch Examples - -You can watch Nightwatch running in real time at https://drupal.ddev.site:7900 -for Chrome and https://drupal.ddev.site:7901 for Firefox. The password is -"secret". YMMV using Firefox as core tests don't currently run on it. - -Only core tests -``` -ddev nightwatch --tag core -``` - -Skip running core tests -``` -ddev nightwatch --skiptags core -``` - -Run a single test -``` -ddev nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js -``` - -a11y tests for both the admin and default themes -``` -ddev nightwatch --tag a11y -``` - -a11y tests for the admin theme only -``` -ddev nightwatch --tag a11y:admin -``` - -a11y tests for the default theme only -``` -ddev nightwatch --tag a11y:default -``` - -a11y test for a custom theme used as the default theme -``` -ddev nightwatch --tag a11y:default --defaultTheme bartik -``` - -a11y test for a custom admin theme -``` -ddev nightwatch --tag a11y:admin --adminTheme seven -``` +# ddev-core-dev + +This is a DDEV addon for doing Drupal core development. + +We're in #ddev-for-core-dev on [Drupal Slack](https://www.drupal.org/community/contributor-guide/reference-information/talk/tools/slack) (but please try and keep work and feature requests in Issues where it's visible to all 🙏) + +`ddev drush` is fully supported, along with using or testing MariaDB, MySQL, and PostgreSQL databases (and Sqlite3) + + +``` +git clone https://git.drupalcode.org/project/drupal.git drupal +cd drupal +ddev config --project-type=drupal +ddev get justafish/ddev-drupal-core-dev +ddev restart +ddev composer install +ddev config --update + + +# Install drupal +ddev drush si -y --account-pass==admin + +# Run PHPUnit tests +ddev phpunit core/modules/sdc + +# Run Nightwatch tests (currently only runs on Chrome) +ddev nightwatch --tag core +``` + +## Using various database types + +By default, the DDEV default database type is used (MariaDB). + +To use another supported database type, +`ddev delete -Oy` and `ddev config --database=mysql:8.0` or `ddev config --database=postgres:16` for example. + +To use Sqlite, +``` +ddev stop +ddev config --disable-settings-management --omit-containers=db +rm -rf web/sites/default/settings*.php web/sites/default/files +ddev start +ddev drupal install +``` + +## Nightwatch Examples + +You can watch Nightwatch running in real time at https://drupal.ddev.site:7900 +for Chrome and https://drupal.ddev.site:7901 for Firefox. The password is +"secret". YMMV using Firefox as core tests don't currently run on it. + +Only core tests +``` +ddev nightwatch --tag core +``` + +Skip running core tests +``` +ddev nightwatch --skiptags core +``` + +Run a single test +``` +ddev nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js +``` + +a11y tests for both the admin and default themes +``` +ddev nightwatch --tag a11y +``` + +a11y tests for the admin theme only +``` +ddev nightwatch --tag a11y:admin +``` + +a11y tests for the default theme only +``` +ddev nightwatch --tag a11y:default +``` + +a11y test for a custom theme used as the default theme +``` +ddev nightwatch --tag a11y:default --defaultTheme bartik +``` + +a11y test for a custom admin theme +``` +ddev nightwatch --tag a11y:admin --adminTheme seven +``` diff --git a/config.core-dev.yaml b/config.core-dev.yaml new file mode 100644 index 0000000..1f71985 --- /dev/null +++ b/config.core-dev.yaml @@ -0,0 +1,31 @@ +# #ddev-generated +# This file is placed by the justafish/ddev-drupal-core-dev addon. + +webimage_extra_packages: ["chromium-driver"] +ddev_version_constraint: '>=v1.23.0' +hooks: + post-start: + - exec: | + dburl='sqlite://localhost/sites/default/files/db.sqlite' + cp .ddev/core-dev/phpunit-chrome.xml core/phpunit.xml + cp .ddev/core-dev/.env core/.env + if ping -c 1 db >/dev/null 2>&1; then + case ${DDEV_DATABASE_FAMILY:-} in + mysql) + # the backslash here is to prevent perl from eating the @ + dburl='mysql://db:db\@db/db' + ;; + postgres) + dburl='pgsql://db:db\@db/db' + ;; + esac + fi + perl -pi -e "s|SIMPLETEST_DB_VALUE|${dburl}|g" core/phpunit.xml + perl -pi -e "s|DRUPAL_TEST_DB_URL_VALUE|${dburl}|g" core/.env + perl -pi -e "s|DRUPAL_CORE_DDEV_URL|${DDEV_PRIMARY_URL}|g" core/phpunit.xml + +upload_dirs: + # The install technique tries to remove all of sites/default/files + # but with DDEV + mutagen that isn't possible. + # so just redirect the upload_dirs. + - .ddev/tmp diff --git a/core-dev/.env b/core-dev/.env index 9a54fb3..2b5901d 100644 --- a/core-dev/.env +++ b/core-dev/.env @@ -19,7 +19,7 @@ DRUPAL_TEST_BASE_URL=http://web # By default we use sqlite as database. Use # mysql://username:password@localhost/databasename#table_prefix for mysql. -DRUPAL_TEST_DB_URL=sqlite://localhost/sites/default/files/db.sqlite +DRUPAL_TEST_DB_URL=DRUPAL_TEST_DB_URL_VALUE ############# # Webdriver # diff --git a/core-dev/phpunit-chrome.xml b/core-dev/phpunit-chrome.xml index a4888bd..8e5e47c 100644 --- a/core-dev/phpunit-chrome.xml +++ b/core-dev/phpunit-chrome.xml @@ -1,103 +1,102 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ./tests/TestSuites/UnitTestSuite.php - - - ./tests/TestSuites/KernelTestSuite.php - - - ./tests/TestSuites/FunctionalTestSuite.php - - - ./tests/TestSuites/FunctionalJavascriptTestSuite.php - - - ./tests/TestSuites/BuildTestSuite.php - - - - - - - - - - ./includes - ./lib - ./modules - ../modules - ../sites - - - ./modules/*/src/Tests - ./modules/*/tests - ../modules/*/src/Tests - ../modules/*/tests - ../modules/*/*/src/Tests - ../modules/*/*/tests - ./lib/** - ./modules/** - ../modules/** - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ./tests/TestSuites/UnitTestSuite.php + + + ./tests/TestSuites/KernelTestSuite.php + + + ./tests/TestSuites/FunctionalTestSuite.php + + + ./tests/TestSuites/FunctionalJavascriptTestSuite.php + + + ./tests/TestSuites/BuildTestSuite.php + + + + + + + + + + ./includes + ./lib + ./modules + ../modules + ../sites + + + ./modules/*/src/Tests + ./modules/*/tests + ../modules/*/src/Tests + ../modules/*/tests + ../modules/*/*/src/Tests + ../modules/*/*/tests + ./lib/** + ./modules/** + ../modules/** + + + diff --git a/core-dev/phpunit-firefox.xml b/core-dev/phpunit-firefox.xml index 564f83c..109c9f7 100644 --- a/core-dev/phpunit-firefox.xml +++ b/core-dev/phpunit-firefox.xml @@ -1,103 +1,102 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ./tests/TestSuites/UnitTestSuite.php - - - ./tests/TestSuites/KernelTestSuite.php - - - ./tests/TestSuites/FunctionalTestSuite.php - - - ./tests/TestSuites/FunctionalJavascriptTestSuite.php - - - ./tests/TestSuites/BuildTestSuite.php - - - - - - - - - - ./includes - ./lib - ./modules - ../modules - ../sites - - - ./modules/*/src/Tests - ./modules/*/tests - ../modules/*/src/Tests - ../modules/*/tests - ../modules/*/*/src/Tests - ../modules/*/*/tests - ./lib/** - ./modules/** - ../modules/** - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ./tests/TestSuites/UnitTestSuite.php + + + ./tests/TestSuites/KernelTestSuite.php + + + ./tests/TestSuites/FunctionalTestSuite.php + + + ./tests/TestSuites/FunctionalJavascriptTestSuite.php + + + ./tests/TestSuites/BuildTestSuite.php + + + + + + + + + + ./includes + ./lib + ./modules + ../modules + ../sites + + + ./modules/*/src/Tests + ./modules/*/tests + ../modules/*/src/Tests + ../modules/*/tests + ../modules/*/*/src/Tests + ../modules/*/*/tests + ./lib/** + ./modules/** + ../modules/** + + + diff --git a/install.yaml b/install.yaml index d46bac3..b050f7a 100644 --- a/install.yaml +++ b/install.yaml @@ -3,7 +3,7 @@ name: ddev-drupal-core-dev project_files: - - config.ddev-drupal-core-dev.yaml + - config.core-dev.yaml - docker-compose.core-dev-selenium.yaml - core-dev/phpunit-firefox.xml - core-dev/phpunit-chrome.xml @@ -22,13 +22,9 @@ project_files: - core-dev/src/Command/UninstallCommand.php post_install_actions: - - cp core-dev/phpunit-chrome.xml ../core/phpunit.xml - - perl -pi -e "s|DRUPAL_CORE_DDEV_URL|$DDEV_PRIMARY_URL|g" ../core/phpunit.xml - - cp core-dev/.env ../core/.env - cp core-dev/gitignore ../.gitignore - mkdir -p ../test_output - chmod +w ../test_output - - cd ../core && ddev yarn removal_actions: - |