Skip to content

Commit 67630ca

Browse files
authored
Enhance Behat writing documentation with specific examples
Added examples on configuration settings, autocomplete options, language packs, and Moodle version requirements for Behat tests.
1 parent 4f3e494 commit 67630ca

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

general/development/tools/behat/writing.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,81 @@ When I set the following fields to these values:
258258
| myDate[year] | ##yesterday##%Y## |
259259
```
260260

261+
#### Configuration settings
262+
263+
For some tests you may need special configurations be present in you Moodle. These can be set as follows:
264+
265+
```gherkin
266+
Given the following config values are set as admin:
267+
| config_key | config value (as it is saved in the DB) | plugin_name |
268+
```
269+
270+
The first and the second value is mandatory. This is the settings name and
271+
the settings value. For core settings this is just it. There is a 3rd parameter
272+
for the plugin name. In the GUI for the above setting below the label you would
273+
see in small letters the setting name, or the plugin_name/setting_name.
274+
There is an optional fourth value (not used here) possible.
275+
276+
#### Autocomplete options
277+
278+
To test that autocomplete options appear in a list as you type (such as the course search), a test can be witten
279+
in the following way:
280+
281+
```gherkin
282+
And I open the autocomplete suggestions list
283+
When I type "test"
284+
And I should see "Some value" in the ".form-autocomplete-suggestions" "css_element"
285+
And I should see "Some other value" in the ".form-autocomplete-suggestions" "css_element"
286+
```
287+
288+
#### Language packs
289+
290+
For some tests it's important to have more languages installed or that a certain language is present.
291+
In a Behat test you may define installed language packs in this way:
292+
293+
```gherkin
294+
And the following "language packs" exist:
295+
| language |
296+
| fr |
297+
| de |
298+
| es |
299+
```
300+
This would have the additional language packs for French, German ans Spanish installed on the system. English
301+
is still present as well.
302+
303+
With the following test stepts the user may change the language:
304+
305+
```gherkin
306+
Then I follow "Preferences" in the user menu
307+
And I follow "Preferred language"
308+
And I select "de" from the "Preferred language"
309+
```
310+
311+
#### Moodle version
312+
313+
Sometimes it's neccessary that a behat tests runs on a certain version of Moodle only.
314+
315+
A Behat test running in Moodle 4.4 and lower
316+
317+
```gherkin
318+
Scenario: Check some feature in an older version.
319+
Given the site is running Moodle version 4.3 or lower
320+
```
321+
322+
Behat test running in Moodle 4.5 and higher
323+
324+
```gherkin
325+
Scenario: Check some feature in a newer version.
326+
Given the site is running Moodle version 4.5 or higher
327+
```
328+
329+
Behat test running in Moodle 4.2 only
330+
331+
```gherkin
332+
Scenario: Check some feature in Moodle 4.2
333+
Given the site is running Moodle version 4.2
334+
```
335+
261336
### Writing your own steps
262337

263338
Sometimes, you will need to set up data that is specific to your plugin, or perform steps that are specific to your plugin's UI. In this case it may be necessary to [write new step definitions](./writing.md#writing-new-acceptance-test-step-definitions), but the short version is that you define new steps as PHP methods with a special annotation inside a class called `behat_plugintype_plugingname` inside `tests/behat/behat_plugintype_plugingname.php` in your plugin.

0 commit comments

Comments
 (0)