├── .gitignore ├── config └── drupal-branch.php ├── scripts ├── get-drupal.php ├── site-install.sh ├── core-check.php ├── rebuild.sh └── patch-helpers.php ├── rector.php ├── phpunit.xml ├── .lando.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | web 2 | vendor 3 | node_modules 4 | /*.patch 5 | *.sql 6 | *.sql.gz 7 | *.gz 8 | -------------------------------------------------------------------------------- /config/drupal-branch.php: -------------------------------------------------------------------------------- 1 | > /app/web/.gitignore 8 | echo ".gitignore\nsites/simpletest" >> /app/web/.gitignore 9 | echo "sites/default/files" >> /app/web/.gitignore 10 | echo "sites/default/settings.php" >> /app/web/.gitignore 11 | -------------------------------------------------------------------------------- /rector.php: -------------------------------------------------------------------------------- 1 | sets([ 15 | Drupal8SetList::DRUPAL_8, 16 | Drupal9SetList::DRUPAL_9, 17 | ]); 18 | 19 | $parameters = $rectorConfig->parameters(); 20 | 21 | $drupalFinder = new DrupalFinder(); 22 | // Use the appropriate folder so DrupalFinder knows what to do. 23 | $drupalFinder->locateRoot(__DIR__ . '/web'); 24 | $drupalRoot = $drupalFinder->getDrupalRoot(); 25 | $rectorConfig->autoloadPaths([ 26 | $drupalRoot . '/core', 27 | $drupalRoot . '/modules', 28 | $drupalRoot . '/profiles', 29 | $drupalRoot . '/themes' 30 | ]); 31 | 32 | $rectorConfig->skip(['*/upgrade_status/tests/modules/*']); 33 | $rectorConfig->fileExtensions(['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); 34 | $rectorConfig->importNames(true, false); 35 | $rectorConfig->importShortClasses(false); 36 | $parameters->set('drupal_rector_notices_as_comments', true); 37 | }; 38 | -------------------------------------------------------------------------------- /scripts/patch-helpers.php: -------------------------------------------------------------------------------- 1 | /app/$branch.patch && 77 | git reset HEAD" 78 | ); 79 | } 80 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ./web/core/tests/TestSuites/UnitTestSuite.php 23 | 24 | 25 | ./web/core/tests/TestSuites/KernelTestSuite.php 26 | 27 | 28 | ./web/core/tests/TestSuites/FunctionalTestSuite.php 29 | 30 | 31 | ./web/core/tests/TestSuites/FunctionalJavascriptTestSuite.php 32 | 33 | 34 | ./web/core//tests/TestSuites/BuildTestSuite.php 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | ./web/core/includes 48 | ./web/core/lib 49 | 50 | ./web/core/modules 51 | 52 | ./web/core/modules/*/src/Tests 53 | ./web/core/modules/*/tests 54 | 55 | ./web/modules 56 | 57 | ./web/modules/*/src/Tests 58 | ./web/modules/*/tests 59 | ./web/modules/*/*/src/Tests 60 | ./web/modules/*/*/tests 61 | 62 | ./web/sites 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /.lando.yml: -------------------------------------------------------------------------------- 1 | name: drupal-contributions 2 | recipe: drupal9 3 | config: 4 | webroot: web 5 | xdebug: 'debug' 6 | services: 7 | appserver: 8 | build_as_root: 9 | # Note that you will want to use the script for the major version of node you want to install 10 | # See: https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions 11 | - curl -sL https://deb.nodesource.com/setup_16.x | bash - 12 | - apt-get install -y nodejs 13 | - npm install --global yarn 14 | - rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && /etc/init.d/apache2 reload 15 | run: 16 | - cd /app/web && composer require drush/drush palantirnet/drupal-rector && composer install 17 | - mkdir -p private/browsertest_output 18 | - yarn install --non-interactive --cwd /app/web/core 19 | overrides: 20 | environment: 21 | SIMPLETEST_BASE_URL: "https://drupal-contributions.lndo.site/" 22 | SIMPLETEST_DB: "sqlite://localhost/tmp/db.sqlite" 23 | BROWSERTEST_OUTPUT_DIRECTORY: '/app/web/sites/simpletest/browser_output' 24 | BROWSERTEST_OUTPUT_BASE_URL: 'https://drupal-contributions.lndo.site' 25 | MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox"]}}, "http://chrome:9515"]' 26 | # Nightwatch 27 | DRUPAL_TEST_BASE_URL: 'http://appserver' 28 | DRUPAL_TEST_DB_URL: 'mysql://drupal9:drupal9@database:3306/drupal9' 29 | DRUPAL_TEST_WEBDRIVER_HOSTNAME: chrome 30 | DRUPAL_TEST_WEBDRIVER_PORT: 9515 31 | DRUPAL_TEST_CHROMEDRIVER_AUTOSTART: 'false' 32 | DRUPAL_TEST_WEBDRIVER_CHROME_ARGS: "--disable-gpu --headless --no-sandbox" 33 | DRUPAL_NIGHTWATCH_OUTPUT: reports/nightwatch 34 | DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES: node_modules,vendor,.*,sites/*/files,sites/*/private,sites/simpletest 35 | chrome: 36 | type: compose 37 | app_mount: false 38 | services: 39 | image: drupalci/webdriver-chromedriver:production 40 | command: chromedriver --log-path=/tmp/chromedriver.log --allowed-origins=* --verbose --whitelisted-ips= 41 | 42 | tooling: 43 | drush: 44 | service: appserver 45 | cmd: 46 | web/vendor/drush/drush/drush --root=/app/web --uri=https://drupal-contributions.lndo.site 47 | rector: 48 | service: appserver 49 | cmd: web/vendor/bin/rector 50 | si: 51 | service: appserver 52 | description: Install Drupal 53 | cmd: 54 | - appserver: /app/scripts/site-install.sh 55 | patch: 56 | service: appserver 57 | description: Get a patch from a Drupal project issue queue 58 | cmd: 59 | - appserver: php /app/scripts/patch-helpers.php 60 | options: 61 | url: 62 | describe: The url of the patch from the issue queue 63 | revert: 64 | service: appserver 65 | description: Apply a patch from a Drupal project issue queue 66 | cmd: 67 | - appserver: php /app/scripts/patch-helpers.php --revert 68 | patch: 69 | describe: The name of the patch to revert; i.e. DESCRIPTION-XXXXXXX-YY.patch 70 | create-patch: 71 | service: appserver 72 | description: Creat a patch from your committed changes on your branch. 73 | cmd: 74 | - appserver: php /app/scripts/patch-helpers.php --create-patch 75 | phpunit: 76 | service: appserver 77 | user: www-data 78 | cmd: 79 | - appserver: php /app/web/vendor/bin/phpunit -c /app/phpunit.xml 80 | 81 | core-check: 82 | service: appserver 83 | cmd: 84 | - appserver: php /app/scripts/core-check.php 85 | 86 | nightwatch: 87 | service: appserver 88 | description: Run Nightwatch.js 89 | cmd: yarn test:nightwatch 90 | dir: /app/web/core 91 | 92 | xdebug-on: 93 | service: appserver 94 | description: Enable xdebug for Apache. 95 | cmd: rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && docker-php-ext-enable xdebug && /etc/init.d/apache2 reload && echo "Xdebug enabled" 96 | user: root 97 | 98 | xdebug-off: 99 | service: appserver 100 | description: Disable xdebug for Apache. 101 | cmd: rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && /etc/init.d/apache2 reload && echo "Xdebug disabled" 102 | user: root 103 | 104 | events: 105 | post-start: 106 | - if [ ! -d web ] ; then php /app/scripts/get-drupal.php ; fi 107 | post-destroy: 108 | - chmod 777 -R web/sites/default 109 | - echo "Removing web/" && rm -rf /app/web 110 | pre-rebuild: 111 | - echo "Removing web/" && rm -rf web 112 | - appserver: php /app/scripts/get-drupal.php 113 | post-rebuild: 114 | - appserver: /app/scripts/rebuild.sh 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Looking For Maintainer](https://img.shields.io/badge/maintenance-looking--for--maintainer-orange.svg) 2 | 3 | # Lando + Drupal Contributions 4 | 5 | This repo is intended to make it easy to contribute to the [Drupal core](https://drupal.org/project/drupal) and contrib projects. 6 | 7 | - [Lando + Drupal Contributions](#lando--drupal-contributions) 8 | - [Why?](#why) 9 | - [How?](#how) 10 | - [Testing Drupal Patches](#testing-drupal-patches) 11 | - [Test a Core Patch](#test-a-core-patch) 12 | - [Test a Contrib Module Patch](#test-a-contrib-module-patch) 13 | - [Creating a Patch](#creating-a-patch) 14 | - [Core Patch Example](#core-patch-example) 15 | - [Contrib Module Example](#contrib-module-example) 16 | - [Running Tests](#running-tests) 17 | - [PHPUnit](#phpunit) 18 | - [Nightwatch](#nightwatch) 19 | - [La Fin](#la-fin) 20 | 21 | ## Why? 22 | 23 | Setting up, testing, and writing Drupal patches can be a confusing gauntlet to the uninitiated, [lando/drupal-contributions](https://github.com/lando/drupal-contributions) this project automates as much of the process as possible. 24 | 25 | The spin ups should be considered completely ephemeral as on every `lando rebuild` events will be fired to tear down the current code base and rewrite the database with a fresh install. 26 | 27 | Using this repo gives you a `.lando.yml` file configured for Drupal contributions: 28 | 29 | - Automatically grabs the Drupal source code and runs `composer install` on `lando rebuild -y` 30 | - Automatically kills the source code and database on `lando rebuild -y` so you can start fresh with each patch 31 | - Adds a `lando phpunit` command to invoke PHPUnit tests 32 | - Adds a `lando si` command to reinstall the site with fresh DB if you need one (without rebuilding) 33 | - Adds a `lando patch URL` command to pull down and apply a patch from drupal.org 34 | - Adds a `lando revert PATCH_NAME` command should you need/want to revert a patch 35 | - Adds a `lando core-check` coommand to check code standards and spelling 36 | - Adds a `lando create-patch` coommand to create a patch from the current branch 37 | 38 | ## How? 39 | 40 | Video presentation: [SFDUG - June 25 - Lando for Contrib / LLC, Corporation or Sole Prop/Partnership](https://www.youtube.com/watch?v=vVpKCQZKNtM) 41 | 42 | Let's step through how to spin up your contribution workflow. First clone down this repo: 43 | 44 | ``` 45 | git clone git@github.com:lando/drupal-contributions.git 46 | cd drupal-contributions 47 | ``` 48 | 49 | This gets us the `.lando.yml` config and scripts to glue all the processes together. 50 | 51 | Next `rebuild` the `drupal-contributions` app: 52 | 53 | > **_NOTE:_** Please note that we are using `rebuild` and not the `start` command. Rebuild has the events to trigger getting the Drupal source code and installation. 54 | 55 | ``` 56 | lando rebuild -y 57 | ``` 58 | 59 | This will pull in the drupal source code from the latest `9.x-dev` branch, run `composer install` to get dependencies, install Drupal, and provide us with a one time login link (`uli`). You can update the version in the `/config/drupal-branch.php` file. 60 | 61 | After `rebuild` completes you should see something similar to this: 62 | 63 | ``` 64 | ___ __ __ __ __ ______ 65 | / _ )___ ___ __ _ ___ / / ___ _/ /_____ _/ /__ _/ /_____ _/ / / / 66 | / _ / _ \/ _ \/ ' \(_-> core/CHANGELOG.txt 170 | git add core/CHANGELOG.txt 171 | git commit -m "Updates CHANGELOG.txt" 172 | lando core-check 173 | lando create-patch 174 | ``` 175 | 176 | #### Contrib Module Example 177 | 178 | To create a contrib module patch, for example [Admin Toolbar](https://www.drupal.org/project/admin_toolbar), download it to the modules folder, following the instructions under [Version control](https://www.drupal.org/project/admin_toolbar/git-instructions): 179 | 180 | ``` 181 | cd web/modules 182 | git clone --branch 8.x-2.x https://git.drupalcode.org/project/admin_toolbar.git 183 | ``` 184 | 185 | Inside the contrib module folder, create a branch in the format `ISSUE####-COMMENT#`. For example: 186 | 187 | ``` 188 | cd admin_toolbar 189 | git checkout -b 1234567-admin_toolbar-improved-paths 190 | ``` 191 | 192 | Make your changes. 193 | 194 | ``` 195 | ...(code code code)... 196 | ``` 197 | 198 | Test your changes. For example: 199 | 200 | ``` 201 | cd ../drupal-contributions; 202 | lando phpunit --group admin_toolbar; 203 | 204 | // or run a single test 205 | 206 | lando phpunit web/modules/admin_toolbar/tests/src/Functional/AdminToolbarAlterTest.php 207 | ``` 208 | 209 | When you are ready, add/commit the relevant changes and create the patch. For example: 210 | 211 | ``` 212 | 213 | git add this.php that.js 214 | git commit -m "Your commit message" 215 | 216 | // While still on your patch branch, git diff the module's dev branch and redirect its output to a file in the format ISSUE####-COMMENT#.patch. For example: 217 | 218 | git diff 8.x-2.x > 1234567-admin_toolbar-improved-paths.patch 219 | ``` 220 | 221 | Verify your own contrib module patch against the module's dev branch. For example: 222 | 223 | ``` 224 | git checkout 8.x-2.x; 225 | git apply -v 1234567-admin_toolbar-improved-paths.patch; 226 | 227 | // Verify output of above command is: 228 | 229 | Checking patch... 230 | Applied patch...cleanly. 231 | ``` 232 | 233 | If the patch works, upload it to the drupal.org contrib module issue. 234 | 235 | ## Running Tests 236 | 237 | #### PHPUnit 238 | PHPUnit runs all the tests in Drupal 8 and above, to run tests with [PHPUnit](https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/running-phpunit-tests): 239 | 240 | List all tests groups: 241 | 242 | ``` 243 | lando phpunit --list-groups 244 | ``` 245 | 246 | Run one group of tests, for example BigPipe: 247 | 248 | ``` 249 | lando phpunit --group big_pipe 250 | ``` 251 | 252 | Run multiple groups of tests: 253 | 254 | ``` 255 | lando phpunit --group Group1,Group2 256 | ``` 257 | 258 | Exclude a group of tests: 259 | 260 | ``` 261 | lando phpunit --exclude-group Groupname 262 | ``` 263 | 264 | Run a single test, the Drupal core password hashing API: 265 | 266 | ``` 267 | lando phpunit web/core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php 268 | ``` 269 | 270 | #### Nightwatch 271 | 272 | To run only core tests, run: 273 | 274 | ``` 275 | lando nightwatch --tag core 276 | ``` 277 | 278 | To skip running core tests, run: 279 | 280 | ``` 281 | lando nightwatch --skiptags core 282 | ``` 283 | 284 | To run a single test, run e.g: 285 | 286 | ``` 287 | lando nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js 288 | ``` 289 | 290 | ## La Fin 291 | 292 | Once you have the latest `9.x-dev` branch you can keep it and sync it periodically and `lando start`'s will keep that around. If you want to totally start fresh: 293 | 294 | ``` 295 | # destroys drupal-contributions app and removes /web 296 | lando destroy -y 297 | 298 | # Spin up a fresh checkout of Drupal source installed and ready 299 | # for dev, patching, and testing. 300 | lando rebuild -y 301 | ``` 302 | 303 | *Original text from [Lando + Drupal Contributions](https://lando.dev/blog/2020/06/02/lando-drupal-contributions/) by [Geoff St. Pierre](https://twitter.com/serundeputy).* 304 | --------------------------------------------------------------------------------