diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 0633b21dc00..6e1e26f8a13 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -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' + ); + } + } + } diff --git a/lib/tests/behat/min_max_version.feature b/lib/tests/behat/min_max_version.feature new file mode 100644 index 00000000000..c7a6201aea6 --- /dev/null +++ b/lib/tests/behat/min_max_version.feature @@ -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"