MDL-40566 behat: Moving from behat_command to behat_selectors

This commit is contained in:
David Monllao
2013-09-03 11:10:30 +08:00
parent 79b2f3a6f9
commit 9ae0496854
4 changed files with 15 additions and 45 deletions
+3 -3
View File
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/behat/classes/behat_command.php');
require_once($CFG->libdir . '/behat/classes/behat_selectors.php');
/**
* Renderer for behat tool web features
@@ -92,7 +92,7 @@ class tool_behat_renderer extends plugin_renderer_base {
// Replace text selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_command::$allowedtextselectors, uniqid());
return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
},
$stepsdefinitions
);
@@ -100,7 +100,7 @@ class tool_behat_renderer extends plugin_renderer_base {
// Replace selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_command::$allowedselectors, uniqid());
return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
},
$stepsdefinitions
);
+6 -14
View File
@@ -367,22 +367,13 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
*/
protected function transform_selector($selectortype, $element) {
// Here we don't know if a $allowedtextselector is used.
if (!isset(behat_command::$allowedselectors[$selectortype])) {
// Here we don't know if an allowed text selector is being used.
$selectors = behat_selectors::get_allowed_selectors();
if (!isset($selectors[$selectortype])) {
throw new ExpectationException('The "' . $selectortype . '" selector type does not exist', $this->getSession());
}
// CSS and XPath selectors locator is one single argument.
if ($selectortype == 'css_element' || $selectortype == 'xpath_element') {
$selector = str_replace('_element', '', $selectortype);
$locator = $element;
} else {
// Named selectors uses arrays as locators including the type of named selector.
$locator = array($selectortype, $this->getSession()->getSelectorsHandler()->xpathLiteral($element));
$selector = 'named';
}
return array($selector, $locator);
return behat_selectors::get_behat_selector($selectortype, $element, $this->getSession());
}
/**
@@ -398,7 +389,8 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
*/
protected function transform_text_selector($selectortype, $element) {
if ($selectortype != 'css_element' && $selectortype != 'xpath_element') {
$selectors = behat_selectors::get_allowed_text_selectors();
if (empty($selectors[$selectortype])) {
throw new ExpectationException('The "' . $selectortype . '" selector can not be used to select text nodes', $this->getSession());
}
-28
View File
@@ -42,34 +42,6 @@ class behat_command {
*/
const DOCS_URL = 'http://docs.moodle.org/dev/Acceptance_testing';
/**
* @var Allowed types when using text selectors arguments.
*/
public static $allowedtextselectors = array(
'css_element' => 'css_element',
'xpath_element' => 'xpath_element'
);
/**
* @var Allowed types when using selector arguments.
*/
public static $allowedselectors = array(
'link' => 'link',
'button' => 'button',
'link_or_button' => 'link_or_button',
'select' => 'select',
'checkbox' => 'checkbox',
'radio' => 'radio',
'file' => 'file',
'optgroup' => 'optgroup',
'option' => 'option',
'table' => 'table',
'field' => 'field',
'fieldset' => 'fieldset',
'css_element' => 'css_element',
'xpath_element' => 'xpath_element'
);
/**
* Ensures the behat dir exists in moodledata
* @return string Full path
+6
View File
@@ -89,6 +89,7 @@ class behat_hooks extends behat_base {
// Now that we are MOODLE_INTERNAL.
require_once(__DIR__ . '/../../behat/classes/behat_command.php');
require_once(__DIR__ . '/../../behat/classes/behat_selectors.php');
require_once(__DIR__ . '/../../behat/classes/util.php');
require_once(__DIR__ . '/../../testing/classes/test_lock.php');
require_once(__DIR__ . '/../../testing/classes/nasty_strings.php');
@@ -138,6 +139,11 @@ class behat_hooks extends behat_base {
throw new coding_exception('Behat only can modify the test database and the test dataroot!');
}
// We need the Mink session to do it and we do it only before the first scenario.
if (self::is_first_scenario()) {
behat_selectors::register_moodle_selectors($this->getSession());
}
// Avoid some notices / warnings.
$SESSION = new stdClass();