MDL-76731 behat: add steps to check for version

Co-authored-by: Andrew Nicols <andrew@nicols.co.uk>
This commit is contained in:
Philipp Imhof 2022-12-20 12:02:28 +01:00
parent 15a695d573
commit 75be72b2d6
No known key found for this signature in database
GPG Key ID: B0855563879F8BC9
2 changed files with 66 additions and 0 deletions

View File

@ -2248,4 +2248,43 @@ EOF;
// Set the list new list of editors.
set_config('texteditors', implode(',', $list));
}
/**
* Allow to check for minimal Moodle version.
*
* @Given the site is running Moodle version :minversion or higher
* @param string $minversion The minimum version of Moodle required (inclusive).
*/
public function the_site_is_running_moodle_version_or_higher(string $minversion): void {
global $CFG;
require_once($CFG->libdir . '/environmentlib.php');
$currentversion = normalize_version(get_config('', 'release'));
if (version_compare($currentversion, $minversion, '<')) {
throw new Moodle\BehatExtension\Exception\SkippedException(
'Site must be running Moodle version ' . $minversion . ' or higher'
);
}
}
/**
* Allow to check for maximum Moodle version.
*
* @Given the site is running Moodle version :maxversion or lower
* @param string $maxversion The maximum version of Moodle required (inclusive).
*/
public function the_site_is_running_moodle_version_or_lower(string $maxversion): void {
global $CFG;
require_once($CFG->libdir . '/environmentlib.php');
$currentversion = normalize_version(get_config('', 'release'));
if (version_compare($currentversion, $maxversion, '>')) {
throw new Moodle\BehatExtension\Exception\SkippedException(
'Site must be running Moodle version ' . $maxversion . ' or lower'
);
}
}
}

View File

@ -0,0 +1,27 @@
@core
Feature: Check for minimum or maximimum version of Moodle
In order adapt acceptance tests for different versions of Moodle
As a developer
I should be able to skip tests according to the Moodle version present on a site
Scenario: Minimum version too low
Given the site is running Moodle version 99.0 or higher
# The following steps should not be executed. If they are, the test will fail.
When I log in as "admin"
Then I should not see "Home"
Scenario: Maximum version too high
Given the site is running Moodle version 3.0 or lower
# The following steps should not be executed. If they are, the test will fail.
When I log in as "admin"
Then I should not see "Home"
Scenario: Minimum version OK
Given the site is running Moodle version 3.0 or higher
When I log in as "admin"
Then I should see "Home"
Scenario: Maximum version OK
Given the site is running Moodle version 99.0 or lower
When I log in as "admin"
Then I should see "Home"