Skip to content

Commit d701390

Browse files
committed
Enhance Behat writing documentation with specific examples.
The additions provide practical guidance for developers writing Behat tests in Moodle environments. * Added documentation for configuration settings, autocomplete testing, language pack setup, and version-specific tests * Included code examples with Gherkin syntax for each new section * Provided specific implementation details for testing various Moodle features
1 parent 4f3e494 commit d701390

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

general/development/tools/behat/writing.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,82 @@ 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 to 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 written
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+
301+
This would have the additional language packs for French, German and Spanish installed on the system. English
302+
is still present as well.
303+
304+
With the following test steps the user may change the language:
305+
306+
```gherkin
307+
Then I follow "Preferences" in the user menu
308+
And I follow "Preferred language"
309+
And I select "de" from the "Preferred language"
310+
```
311+
312+
#### Moodle version
313+
314+
Sometimes it's necessary that a Behat test runs on a certain version of Moodle only.
315+
316+
A Behat test running in Moodle 4.4 and lower
317+
318+
```gherkin
319+
Scenario: Check some feature in an older version.
320+
Given the site is running Moodle version 4.3 or lower
321+
```
322+
323+
Behat test running in Moodle 4.5 and higher
324+
325+
```gherkin
326+
Scenario: Check some feature in a newer version.
327+
Given the site is running Moodle version 4.5 or higher
328+
```
329+
330+
Behat test running in Moodle 4.2 only
331+
332+
```gherkin
333+
Scenario: Check some feature in Moodle 4.2
334+
Given the site is running Moodle version 4.2
335+
```
336+
261337
### Writing your own steps
262338

263339
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)