5 * Run the functional tests:
7 export SIMPLETEST_DB='mysql://root@localhost/dev_d8'
8 export SIMPLETEST_BASE_URL='http://d8.dev'
9 ./vendor/bin/phpunit -c core --testsuite functional
12 Note: functional tests have to be invoked with a user in the same group as the
13 web server user. You can either configure Apache (or nginx) to run as your own
14 system user or run tests as a privileged user instead.
16 Invoking tests with a user that is in the same group as the web server will
17 require you to ensure Drupal keeps gid stickybits when creating new directories.
19 `$settings['file_chmod_directory'] = 02775;`
21 To develop locally, a straightforward - but also less secure - approach is to
22 run tests as your own system user. To achieve that, change the default Apache
23 user to run as your system user. Typically, you'd need to modify
24 `/etc/apache2/envvars` on Linux or `/etc/apache2/httpd.conf` on Mac.
29 export APACHE_RUN_USER=<your-user>
30 export APACHE_RUN_GROUP=<your-group>
40 ## Functional javascript tests
42 Javascript tests use the Selenium2Driver which allows you to control a
43 big range of browsers. By default Drupal uses chromedriver to run tests.
44 For help installing and starting selenium, see http://mink.behat.org/en/latest/drivers/selenium2.html
46 * Make sure you have a recent version of chrome installed
48 * Install selenium-server-standalone and chromedriver
53 brew install selenium-server-standalone
54 brew install chromedriver
57 * Before running tests make sure that selenium-server is running
59 selenium-server -port 4444
62 * Set the correct driver args and run the tests:
64 export MINK_DRIVER_ARGS_WEBDRIVER='["chrome", null, "http://localhost:4444/wd/hub"]'
65 ./vendor/bin/phpunit -c core --testsuite functional-javascript
68 * It is possible to use alternate browsers if the required dependencies are
69 installed. For example to use Firefox:
72 export MINK_DRIVER_ARGS_WEBDRIVER='["firefox", null, "http://localhost:4444/wd/hub"]'
73 ./vendor/bin/phpunit -c core --testsuite functional-javascript
76 * To force all BrowserTestBase (including legacy JavascriptTestBase) tests to use
80 export MINK_DRIVER_CLASS='Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver'
81 ./vendor/bin/phpunit -c core --testsuite functional-javascript
84 ## Running legacy javascript tests
86 Older javascript test may use the PhantomJSDriver. To run these tests you will
87 have to install and start PhantomJS.
91 phantomjs --ssl-protocol=any --ignore-ssl-errors=true ./vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /dev/null &
94 * Then you can run the test:
96 ./vendor/bin/phpunit -c core --testsuite functional-javascript
99 ## Running tests with a different user
101 If the default user is e.g. `www-data`, the above functional tests will have to
102 be invoked with sudo instead:
105 export SIMPLETEST_DB='mysql://root@localhost/dev_d8'
106 export SIMPLETEST_BASE_URL='http://d8.dev'
107 sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite functional
108 sudo -u www-data -E ./vendor/bin/phpunit -c core --testsuite functional-javascript
113 - Ensure your vendor directory is populated (e.g. by running `composer install`)
114 - If you're running PHP 7.0 or greater you will need to upgrade PHPUnit with `composer run-script drupal-phpunit-upgrade`
115 - Install [Node.js](https://nodejs.org/en/download/) and [yarn](https://yarnpkg.com/en/docs/install). The versions required are specificed inside core/package.json in the `engines` field
116 - Install [Google Chrome](https://www.google.com/chrome/browser/desktop/index.html)
117 - Inside the `core` folder, run `yarn install`
118 - Configure the nightwatch settings by copying `.env.example` to `.env` and editing as necessary.
119 - Ensure you have a web server running (as instructed in `.env`)
120 - Again inside the `core` folder, run `yarn test:nightwatch` to run the tests. By default this will output reports to `core/reports`
121 - Nightwatch will run tests for core, as well as contrib and custom modules and themes. It will search for tests located under folders with the pattern `**/tests/**/Nightwatch/(Tests|Commands|Assertions)`
122 - To run only core tests, run `yarn test:nightwatch --tag core`
123 - To skip running core tests, run `yarn test:nightwatch --skiptags core`
124 - To run a single test, run e.g. `yarn test:nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js`
126 Nightwatch tests can be placed in any folder with the pattern `**/tests/**/Nightwatch/(Tests|Commands|Assertions)`. For example:
128 tests/Nightwatch/Tests
129 src/tests/Nightwatch/Tests
130 tests/src/Nightwatch/Tests
131 tests/Nightwatch/Commands
134 It's helpful to follow existing patterns for test placement, so for the action module they would go in `core/modules/action/tests/src/Nightwatch`.
135 The Nightwatch configuration, as well as global tests, commands, and assertions which span many modules/systems, are located in `core/tests/Drupal/Nightwatch`.
137 If your core directory is located in a subfolder (e.g. `docroot`), then you can edit the search directory in `.env` to pick up tests outside of your Drupal directory.
138 Tests outside of the `core` folder will run in the version of node you have installed. If you want to transpile with babel (e.g. to use `import` statements) outside of core,
139 then add your own babel config to the root of your project. For example, if core is located under `docroot/core`, then you could run `yarn add babel-preset-env` inside
140 `docroot`, then copy the babel settings from `docroot/core/package.json` into `docroot/package.json`.