MDL-63977 Behat: Add generic way to get tag list
This commit is contained in:
@@ -647,6 +647,16 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
|
||||
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 @@ require_once(__DIR__ . '/../../behat/behat_base.php');
|
||||
|
||||
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 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||
* @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 @@ class behat_app extends behat_base {
|
||||
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 @@ class behat_app extends behat_base {
|
||||
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 @@ class behat_hooks extends behat_base {
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user