diff --git a/lib/behat/classes/behat_selectors.php b/lib/behat/classes/behat_selectors.php new file mode 100644 index 00000000000..e92131de93b --- /dev/null +++ b/lib/behat/classes/behat_selectors.php @@ -0,0 +1,161 @@ +. + +/** + * Moodle-specific selectors. + * + * @package core + * @category test + * @copyright 2013 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Moodle selectors manager. + * + * @package core + * @category test + * @copyright 2013 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_selectors { + + /** + * @var Allowed types when using text selectors arguments. + */ + protected static $allowedtextselectors = array( + 'dialogue' => 'dialogue', + 'block' => 'block', + 'region' => 'region', + 'table_row' => 'table_row', + 'table' => 'table', + 'fieldset' => 'fieldset', + 'css_element' => 'css_element', + 'xpath_element' => 'xpath_element' + ); + + /** + * @var Allowed types when using selector arguments. + */ + protected static $allowedselectors = array( + 'dialogue' => 'dialogue', + 'block' => 'block', + 'region' => 'region', + 'table_row' => 'table_row', + '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' + ); + + /** + * Behat by default comes with XPath, CSS and named selectors, + * named selectors are a mapping between names (like button) and + * xpaths that represents that names and includes a placeholder that + * will be replaced by the locator. These are Moodle's own xpaths. + * + * @var XPaths for moodle elements. + */ + protected static $moodleselectors = array( + 'dialogue' => << << << <<getSelectorsHandler()->xpathLiteral($element)); + $selector = 'named'; + } + + return array($selector, $locator); + } + + /** + * Adds moodle selectors as behat named selectors. + * + * @param Session $session The mink session + * @return void + */ + public static function register_moodle_selectors(Behat\Mink\Session $session) { + + foreach (self::get_moodle_selectors() as $name => $xpath) { + $session->getSelectorsHandler()->getSelector('named')->registerNamedXpath($name, $xpath); + } + } + + /** + * Allowed selectors getter. + * + * @return array + */ + public static function get_allowed_selectors() { + return self::$allowedselectors; + } + + /** + * Allowed text selectors getter. + * + * @return array + */ + public static function get_allowed_text_selectors() { + return self::$allowedtextselectors; + } + + /** + * Moodle selectors attribute accessor. + * + * @return array + */ + protected static function get_moodle_selectors() { + return self::$moodleselectors; + } +}