Pull merge.
[yaffs-website] / web / core / tests / README.md
1 # Running tests
2
3 ## Functional tests
4
5 * Run the functional tests:
6   ```
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
10   ```
11
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.
15
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.
18
19 `$settings['file_chmod_directory'] = 02775;`
20
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.
25
26 Example for Linux:
27
28 ```
29 export APACHE_RUN_USER=<your-user>
30 export APACHE_RUN_GROUP=<your-group>
31 ```
32
33 Example for Mac:
34
35 ```
36 User <your-user>
37 Group <your-group>
38 ```
39
40 ## Functional javascript tests
41
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
45
46 * Make sure you have a recent version of chrome installed
47
48 * Install selenium-server-standalone and chromedriver
49
50 Example for Mac:
51
52 ```
53 brew install selenium-server-standalone
54 brew install chromedriver
55 ```
56
57 * Before running tests make sure that selenium-server is running
58 ```
59 selenium-server -port 4444
60 ```
61
62 * Set the correct driver args and run the tests:
63 ```
64 export MINK_DRIVER_ARGS_WEBDRIVER='["chrome", null, "http://localhost:4444/wd/hub"]'
65 ./vendor/bin/phpunit -c core --testsuite functional-javascript
66 ```
67
68 * It is possible to use alternate browsers if the required dependencies are
69 installed. For example to use Firefox:
70
71 ```
72 export MINK_DRIVER_ARGS_WEBDRIVER='["firefox", null, "http://localhost:4444/wd/hub"]'
73 ./vendor/bin/phpunit -c core --testsuite functional-javascript
74 ```
75
76 * To force all BrowserTestBase (including legacy JavascriptTestBase) tests to use
77 webdriver:
78
79 ```
80 export MINK_DRIVER_CLASS='Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver'
81 ./vendor/bin/phpunit -c core --testsuite functional-javascript
82 ```
83
84 ## Running legacy javascript tests
85
86 Older javascript test may use the PhantomJSDriver. To run these tests you will
87 have to install and start PhantomJS.
88
89 * Start PhantomJS:
90   ```
91   phantomjs --ssl-protocol=any --ignore-ssl-errors=true ./vendor/jcalderonzumba/gastonjs/src/Client/main.js 8510 1024 768 2>&1 >> /dev/null &
92   ```
93
94 * Then you can run the test:
95 ```
96 ./vendor/bin/phpunit -c core --testsuite functional-javascript
97 ```
98
99 ## Running tests with a different user
100
101 If the default user is e.g. `www-data`, the above functional tests will have to
102 be invoked with sudo instead:
103
104 ```
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
109 ```
110
111 ## Nightwatch tests
112
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`
125
126 Nightwatch tests can be placed in any folder with the pattern `**/tests/**/Nightwatch/(Tests|Commands|Assertions)`. For example:
127 ```
128 tests/Nightwatch/Tests
129 src/tests/Nightwatch/Tests
130 tests/src/Nightwatch/Tests
131 tests/Nightwatch/Commands
132 ```
133
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`.
136
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`.