From 46e9468a57e9c9ddbd48712ef79fbfa02f9cb689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 1 Jun 2022 11:54:19 +0200 Subject: [PATCH] MOBILE-4061 behat: Check tags when launching the app --- .../tests/behat/behat_app.php | 5 +--- .../tests/behat/behat_app_helper.php | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/local-moodleappbehat/tests/behat/behat_app.php b/local-moodleappbehat/tests/behat/behat_app.php index 6422be3ef..f4d3946ed 100644 --- a/local-moodleappbehat/tests/behat/behat_app.php +++ b/local-moodleappbehat/tests/behat/behat_app.php @@ -82,10 +82,7 @@ class behat_app extends behat_app_helper { * @throws ExpectationException Problem with resizing window */ public function i_launch_the_app(string $runtime = '') { - // Check the app tag was set. - if (!$this->has_tag('app')) { - throw new DriverException('Requires @app tag on scenario or feature.'); - } + $this->check_tags(); // Go to page and prepare browser for app. $this->prepare_browser(['skiponboarding' => empty($runtime)]); diff --git a/local-moodleappbehat/tests/behat/behat_app_helper.php b/local-moodleappbehat/tests/behat/behat_app_helper.php index b2fff6892..57134b662 100644 --- a/local-moodleappbehat/tests/behat/behat_app_helper.php +++ b/local-moodleappbehat/tests/behat/behat_app_helper.php @@ -19,6 +19,7 @@ require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); use Behat\Mink\Exception\DriverException; +use Moodle\BehatExtension\Exception\SkippedException; /** * Behat app listener. @@ -92,7 +93,6 @@ class behat_app_helper extends behat_base { * This updates Moodle configuration and starts Ionic running, if it isn't already. */ public function start_scenario() { - $this->skip_restricted_tags_scenarios(); $this->check_behat_setup(); $this->fix_moodle_setup(); $this->ionicurl = $this->start_or_reuse_ionic(); @@ -623,10 +623,13 @@ EOF; } /** - * Workaround while MDL-74621 is not integrated in all supported versions. - * This function will skip scenarios based on @lms_from and @lms_upto tags. + * This function will skip scenarios based on @lms_from and @lms_upto tags and also missing @app tags. */ - public function skip_restricted_tags_scenarios() { + public function check_tags() { + if (!$this->has_tag('app')) { + throw new DriverException('Requires @app tag on scenario or feature.'); + } + if (is_null($this->lmsversion)) { global $CFG; @@ -644,18 +647,18 @@ EOF; $this->lmsversion = trim($version, '.'); } - if ($this->has_version_restrictions()) { + if ($tag = $this->get_first_restricted_version_tag()) { // Skip this test. - throw new DriverException('Incompatible tags.'); + throw new SkippedException("LMS version $this->lmsversion is not compatible with tag @$tag."); } } /** * Gets if version is incompatible with the @lms_from and @lms_upto tags. * - * @return bool If scenario has any version incompatible tag. + * @return string If scenario has any version incompatible tag, return it. */ - protected function has_version_restrictions() : bool { + protected function get_first_restricted_version_tag(): ?string { $usedtags = behat_hooks::get_tags_for_scenario(); $detectedversioncount = substr_count($this->lmsversion, '.'); @@ -685,15 +688,15 @@ EOF; // Installed version OLDER than the one being considered, so do not // include any scenarios that only run from the considered version up. if ($compare === -1 && $direction === 'from') { - return true; + return $usedtag; } // Installed version NEWER than the one being considered, so do not // include any scenarios that only run up to that version. if ($compare === 1 && $direction === 'upto') { - return true; + return $usedtag; } } - return false; + return null; } }