MDL-37657 behat: Add tree nodes expansion definition
[moodle.git] / lib / tests / behat / behat_navigation.php
CommitLineData
b1bc8cfc
DM
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Navigation steps definitions.
20 *
21 * @package core
22 * @category test
23 * @copyright 2012 David MonllaĆ³
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28
29require_once(__DIR__ . '/../../behat/behat_base.php');
30
31/**
32 * Steps definitions to navigate through the navigation tree nodes.
33 *
34 * @package core
35 * @category test
36 * @copyright 2012 David MonllaĆ³
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class behat_navigation extends behat_base {
40
41 /**
42 * Expands the selected node of the navigation tree that matches the text.
43 *
44 * @Given /^I expand "(?P<nodetext_string>(?:[^"]|\\")*)" node$/
45 * @param string $nodetext
46 */
47 public function i_expand_node($nodetext) {
48
49 $nodetext = $this->fixStepArgument($nodetext);
50
51 $xpath = "//ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]
52/descendant::li
53/descendant::p[contains(concat(' ', normalize-space(@class), ' '), ' branch')]
54/descendant::span[contains(concat(' ', normalize-space(.), ' '), '" . $nodetext . "')]";
55
56 $node = $this->getSession()->getPage()->find('xpath', $xpath);
57 $node->click();
58 }
59
60}