From b1bc8cfc65e681ef7a9a68b23ac28b3eff1f29d7 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Fri, 25 Jan 2013 13:24:07 +0800 Subject: [PATCH] MDL-37657 behat: Add tree nodes expansion definition --- lib/tests/behat/behat_navigation.php | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 lib/tests/behat/behat_navigation.php diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php new file mode 100644 index 00000000000..169e67d9ae7 --- /dev/null +++ b/lib/tests/behat/behat_navigation.php @@ -0,0 +1,60 @@ +. + +/** + * Navigation steps definitions. + * + * @package core + * @category test + * @copyright 2012 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. + +require_once(__DIR__ . '/../../behat/behat_base.php'); + +/** + * Steps definitions to navigate through the navigation tree nodes. + * + * @package core + * @category test + * @copyright 2012 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_navigation extends behat_base { + + /** + * Expands the selected node of the navigation tree that matches the text. + * + * @Given /^I expand "(?P(?:[^"]|\\")*)" node$/ + * @param string $nodetext + */ + public function i_expand_node($nodetext) { + + $nodetext = $this->fixStepArgument($nodetext); + + $xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')] +/descendant::li +/descendant::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')] +/descendant::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]"; + + $node = $this->getSession()->getPage()->find('xpath', $xpath); + $node->click(); + } + +} -- 2.43.0