Skip to content

Commit 34e595e

Browse files
navneet0693paul-m
navneet0693
authored andcommitted
Issue #2833290 by navneet0693, Mile23, eojthebrave, Torenware: TESTING.md does not explain how to test the modules
1 parent 5a505fb commit 34e595e

File tree

2 files changed

+78
-8
lines changed

2 files changed

+78
-8
lines changed

STANDARDS.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ Examples uses mostly the same coding standards as Drupal core.
66
If you see a discrepancy between the coding standards tools used by core and
77
those used by Examples, please file an issue so that Examples can follow core.
88

9-
Examples uses the phpcs tool to allow for checking PHP coding standards. We also
10-
use eslint for JavaScript coding standards.
9+
Examples uses the `phpcs` tool to allow for checking PHP coding standards. We
10+
use the `drupal/coder` project for Drupal-specific coding standards.
1111

12-
Examples has a `phpcs.xml.dist` file at the root of the project. This file
13-
specifies the current coding standards 'sniffs' which code in the project must
14-
pass.
12+
We also use `eslint` for JavaScript coding standards.
1513

16-
The `phpcs.xml.dist` file is used by a tool called PHP_CodeSniffer (`phpcs`).
14+
Examples has a `phpcs.xml.dist` file at the root of the project. phpcs uses this
15+
file to specify the current coding standards 'sniffs' which code in the project
16+
must pass.
1717

1818
Contributors should install `phpcs` in their local Drupal installation, and then
1919
use that to run `phpcs` against Examples as part of their development and review
20-
process.
20+
process. (See details below on how to install and run this tool.)
2121

2222
Contributors can also patch the `phpcs.xml.dist` file itself, in order to fix
2323
the codebase to pass a given rule or sniff. Patches which do this should be
@@ -47,6 +47,10 @@ Like this:
4747
$ ../vendor/bin/phpcs -e --standard=Drupal
4848
// Shows you a bunch of Drupal-related sniffs.
4949

50+
Note that there is an issue to require Coder and phpcs as part of Drupal core:
51+
https://www.drupal.org/node/2744463 Once this issue is fixed, you shouldn't need
52+
to install phpcs before using it.
53+
5054
Running phpcs
5155
-------------
5256

TESTING.md

+67-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ the testbot's behavior.
1515
You can find information on how to run `run-tests.sh` locally here:
1616
https://www.drupal.org/node/645286
1717

18+
Examples is always targeted to the dev branch of Drupal core for the latest
19+
release. As of this writing, the latest release of Drupal core is 8.2.5, which
20+
means development for Examples should be against the Drupal 8.2.x development
21+
branch. When Drupal 8.3.0 is released, we'll start targeting Examples to 8.3.x,
22+
and so on.
23+
1824
You should at least run `run-tests.sh` locally against all the changes in your
1925
patch before uploading it.
2026

@@ -27,8 +33,68 @@ suggested workaround for this, since there is no best practice to demonstrate as
2733
an example. There is, however, this issue in core:
2834
https://www.drupal.org/node/2499239
2935

36+
How To Run The Tests In The Drupal UI
37+
-------------------------------------
38+
39+
Generally, you should run tests from the command line. This is generally easier
40+
than using Drupal's testing UI. However, here's how you can do it that way:
41+
42+
Enable the Testing module.
43+
44+
Visit the test list page at `admin/config/development/testing`.
45+
46+
Since the tests are organized by module, you can search for a module name and
47+
get all the tests for that module. For instance, type in 'node_type_example' for
48+
all the tests related to that module.
49+
50+
Click the check boxes next to the tests you want to run. If you find this
51+
tedious, it's time to learn to use the command line. :-)
52+
53+
Click 'Run Tests.' You're now running the tests.
54+
55+
Step-by-step: How To Run The Tests.
56+
-----------------------------------
57+
58+
Begin with an installed Drupal codebase. Make a codebase, set up the database,
59+
etc. Note that you can use an existing Drupal instance but the best practice is
60+
to start fresh. Something not working right? Try a new installation.
61+
62+
Use the dev branch of core for the latest release of Drupal. As of this writing,
63+
it's 8.2.x. When Drupal 8.3.0 is released, we'll target 8.3.x.
64+
65+
Open the terminal window and move to the root directory of the Drupal
66+
installation:
67+
68+
$ cd path/to/drupal
69+
70+
Put Examples into the `modules/` folder of the Drupal installation. If you are
71+
doing development on Examples, you should have already checked out the git
72+
repository into `modules/`, like this:
73+
74+
$ git clone --branch 8.x-1.x https://git.drupal.org/project/examples.git modules/examples
75+
76+
Now you can run `run-tests.sh`, which, despite having a `.sh` suffix is not a
77+
shell script. It's a PHP script.
78+
79+
You'll use the `--directory` option to have the test runner scan the Examples
80+
module directory for tests.
81+
82+
Also, importantly, if your test site has its own URL, you'll need to supply that
83+
with the `--url` option. For instance, under MAMP, you must specify
84+
`--url http://localhost:8888/`.
85+
86+
You can also use `--concurrency` to speed up the test run, and `--browser` to
87+
see detailed test results in a web browser instead of just text output in the
88+
terminal.
89+
90+
$ php ./core/scripts/run-tests.sh --browser --concurrency 10 --url http://localhost:8888/ --directory modules/examples
91+
92+
This should run all the tests present in Examples. If you add a test and it
93+
doesn't appear in the list of tests to run, then you'll need to double-check
94+
that it's in the proper test namespace and that the class name (and thus the
95+
file name) ends in Test.
3096

31-
What Tests Should An Example Project Have?
97+
What Tests Should An Example Module Have?
3298
------------------------------------------
3399

34100
Examples has a checklist for each module:

0 commit comments

Comments
 (0)