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
// 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
);
// 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
);
*/
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());
}
/**
*/
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());
}
*/
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
// 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');
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();