Skip to content
Permalink
Browse files

MDL-63977 Behat: Add generic way to get tag list

  • Loading branch information...
sammarshallou committed Jan 15, 2019
1 parent d8218a3 commit 66901a69686e2f2f41bbfa35f46ec3ad8666084d
Showing with 40 additions and 16 deletions.
  1. +10 −0 lib/behat/behat_base.php
  2. +1 −16 lib/tests/behat/behat_app.php
  3. +29 −0 lib/tests/behat/behat_hooks.php
@@ -647,6 +647,16 @@ protected function ensure_editors_are_loaded() {
return;
}
/**
* Checks if the current scenario, or its feature, has a specified tag.
*
* @param string $tag Tag to check
* @return bool True if the tag exists in scenario or feature
*/
public function has_tag(string $tag) : bool {
return array_key_exists($tag, behat_hooks::get_tags_for_scenario());
}
/**
* Change browser window size.
* - small: 640x480
@@ -29,7 +29,6 @@
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Exception\ExpectationException;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
/**
* Mobile/desktop app steps definitions.
@@ -40,9 +39,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_app extends behat_base {
/** @var bool True if the current scenario has the app tag */
protected $apptag = false;
/** @var stdClass Object with data about launched Ionic instance (if any) */
protected static $ionicrunning = null;
@@ -55,17 +51,6 @@ protected static function is_windows() : bool {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
/**
* Checks tags before each scenario.
*
* @BeforeScenario
* @param BeforeScenarioScope $scope Scope information
*/
public function check_tags(BeforeScenarioScope $scope) {
$this->apptag = in_array('app', $scope->getScenario()->getTags()) ||
in_array('app', $scope->getFeature()->getTags());
}
/**
* Opens the Moodle app in the browser.
*
@@ -101,7 +86,7 @@ protected function check_behat_setup() {
global $CFG;
// Check the app tag was set.
if (!$this->apptag) {
if (!$this->has_tag('app')) {
throw new DriverException('Requires @app tag on scenario or feature.');
}
@@ -103,6 +103,11 @@ class behat_hooks extends behat_base {
*/
protected static $runningsuite = '';
/**
* @var array Array (with tag names in keys) of all tags in current scenario.
*/
protected static $scenariotags;
/**
* Hook to capture BeforeSuite event so as to give access to moodle codebase.
* This will try and catch any exception and exists if anything fails.
@@ -384,6 +389,30 @@ public function before_scenario(BeforeScenarioScope $scope) {
// Run all test with medium (1024x768) screen size, to avoid responsive problems.
$this->resize_window('medium');
// Set up the tags for current scenario.
self::fetch_tags_for_scenario($scope);
}
/**
* Sets up the tags for the current scenario.
*
* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope Scope
*/
protected static function fetch_tags_for_scenario(\Behat\Behat\Hook\Scope\BeforeScenarioScope $scope) {
self::$scenariotags = array_flip(array_merge(
$scope->getScenario()->getTags(),
$scope->getFeature()->getTags()
));
}
/**
* Gets the tags for the current scenario
*
* @return array Array where key is tag name and value is an integer
*/
public static function get_tags_for_scenario() : array {
return self::$scenariotags;
}
/**

0 comments on commit 66901a6

Please sign in to comment.
You can’t perform that action at this time.