1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Steps definitions to open and close action menus.
|
|
|
19 |
*
|
|
|
20 |
* @package core
|
|
|
21 |
* @category test
|
|
|
22 |
* @copyright 2016 Damyon Wiese
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
|
|
27 |
|
|
|
28 |
require_once(__DIR__ . '/../../behat/behat_base.php');
|
|
|
29 |
|
|
|
30 |
use Behat\Mink\Element\NodeElement;
|
|
|
31 |
use Behat\Mink\Exception\DriverException;
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Steps definitions to open and close action menus.
|
|
|
35 |
*
|
|
|
36 |
* @package core
|
|
|
37 |
* @category test
|
|
|
38 |
* @copyright 2016 Damyon Wiese
|
|
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
40 |
*/
|
|
|
41 |
class behat_action_menu extends behat_base {
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Open the action menu in
|
|
|
45 |
*
|
|
|
46 |
* @Given /^I open the action menu in "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)"$/
|
|
|
47 |
* @param string $element
|
|
|
48 |
* @param string $selector
|
|
|
49 |
* @return void
|
|
|
50 |
*/
|
|
|
51 |
public function i_open_the_action_menu_in($element, $selectortype) {
|
|
|
52 |
// Gets the node based on the requested selector type and locator.
|
|
|
53 |
$node = $this->get_node_in_container(
|
|
|
54 |
"css_element",
|
|
|
55 |
"[role=button][aria-haspopup=true],button[aria-haspopup=true],[role=menuitem][aria-haspopup=true]",
|
|
|
56 |
$selectortype,
|
|
|
57 |
$element
|
|
|
58 |
);
|
|
|
59 |
|
|
|
60 |
// Check if it is not already opened.
|
|
|
61 |
if ($node->getAttribute('aria-expanded') === 'true') {
|
|
|
62 |
return;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
$node->click();
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* When an action menu is open, follow one of the items in it.
|
|
|
70 |
*
|
|
|
71 |
* The > is used to indicate a sub-menu. For example "Group mode > Visible groups"
|
|
|
72 |
* will do two clicks, one on the Group mode menu item, and one on the Visible groups link
|
|
|
73 |
* in the sub-menu.
|
|
|
74 |
*
|
|
|
75 |
* @Given /^I choose "(?P<link_string>(?:[^"]|\\")*)" in the open action menu$/
|
|
|
76 |
* @param string $linkstring
|
|
|
77 |
* @return void
|
|
|
78 |
*/
|
|
|
79 |
public function i_choose_in_the_open_action_menu($menuitemstring) {
|
|
|
80 |
if (!$this->running_javascript()) {
|
|
|
81 |
throw new DriverException('Action menu steps are not available with Javascript disabled');
|
|
|
82 |
}
|
|
|
83 |
// Check for sub-menus.
|
|
|
84 |
$menuitems = explode('>', $menuitemstring);
|
|
|
85 |
foreach ($menuitems as $menuitem) {
|
|
|
86 |
// Gets the node based on the requested selector type and locator.
|
|
|
87 |
$menuselector = ".moodle-actionmenu .dropdown.show .dropdown-menu";
|
|
|
88 |
$node = $this->get_node_in_container("link", trim($menuitem), "css_element", $menuselector);
|
|
|
89 |
$node->click();
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Select a specific item in an action menu.
|
|
|
96 |
*
|
|
|
97 |
* @When /^I choose the "(?P<item_string>(?:[^"]|\\")*)" item in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu$/
|
|
|
98 |
* @param string $item The item to choose
|
|
|
99 |
* @param string $actionmenu The text used in the description of the action menu
|
|
|
100 |
*/
|
|
|
101 |
public function i_choose_in_the_named_menu(string $item, string $actionmenu): void {
|
|
|
102 |
$menu = $this->find('actionmenu', $actionmenu);
|
|
|
103 |
$this->select_item_in_action_menu($item, $menu);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
/**
|
|
|
107 |
* Select a specific item in an action menu within a container.
|
|
|
108 |
*
|
|
|
109 |
* @When /^I choose the "(?P<item_string>(?:[^"]|\\")*)" item in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu of the "(?P<locator_string>(?:[^"]|\\")*)" "(?P<type_string>(?:[^"]|\\")*)"$/
|
|
|
110 |
* @param string $item The item to choose
|
|
|
111 |
* @param string $actionmenu The text used in the description of the action menu
|
|
|
112 |
* @param string|NodeElement $locator The identifer used for the container
|
|
|
113 |
* @param string $selector The type of container to locate
|
|
|
114 |
*/
|
|
|
115 |
public function i_choose_in_the_named_menu_in_container(string $item, string $actionmenu, $locator, $selector): void {
|
|
|
116 |
$container = $this->find($selector, $locator);
|
|
|
117 |
$menu = $this->find('actionmenu', $actionmenu, false, $container);
|
|
|
118 |
$this->select_item_in_action_menu($item, $menu);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Select an item in the specified menu.
|
|
|
123 |
*
|
|
|
124 |
* Note: This step does work both with, and without, JavaScript.
|
|
|
125 |
*
|
|
|
126 |
* @param string $item Item string value
|
|
|
127 |
* @param NodeElement $menu The menu NodeElement to select from
|
|
|
128 |
*/
|
|
|
129 |
protected function select_item_in_action_menu(string $item, NodeElement $menu): void {
|
|
|
130 |
if ($this->running_javascript()) {
|
|
|
131 |
// Open the menu by clicking on the trigger.
|
|
|
132 |
$this->execute(
|
|
|
133 |
'behat_general::i_click_on_in_the',
|
|
|
134 |
['a.dropdown-toggle', 'css_element', $menu, "NodeElement"]
|
|
|
135 |
);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
// Select the menu item.
|
|
|
139 |
$this->execute(
|
|
|
140 |
'behat_general::i_click_on_in_the',
|
|
|
141 |
[$item, "link", $menu, "NodeElement"]
|
|
|
142 |
);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
/**
|
|
|
146 |
* The action menu item should not exist.
|
|
|
147 |
*
|
|
|
148 |
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should not exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu$/
|
|
|
149 |
* @param string $item The item to check
|
|
|
150 |
* @param string $actionmenu The text used in the description of the action menu
|
|
|
151 |
*/
|
|
|
152 |
public function item_should_not_exist(string $item, string $actionmenu): void {
|
|
|
153 |
$menu = $this->find('actionmenu', $actionmenu);
|
|
|
154 |
$this->execute('behat_general::should_not_exist_in_the', [
|
|
|
155 |
$item, 'link',
|
|
|
156 |
$menu, 'NodeElement'
|
|
|
157 |
]);
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
/**
|
|
|
161 |
* The action menu item should not exist within a container.
|
|
|
162 |
*
|
|
|
163 |
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should not exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu of the "(?P<locator_string>(?:[^"]|\\")*)" "(?P<type_string>(?:[^"]|\\")*)"$/
|
|
|
164 |
* @param string $item The item to check
|
|
|
165 |
* @param string $actionmenu The text used in the description of the action menu
|
|
|
166 |
* @param string|NodeElement $locator The identifer used for the container
|
|
|
167 |
* @param string $selector The type of container to locate
|
|
|
168 |
*/
|
|
|
169 |
public function item_should_not_exist_in_the(string $item, string $actionmenu, $locator, $selector): void {
|
|
|
170 |
$container = $this->find($selector, $locator);
|
|
|
171 |
$menu = $this->find('actionmenu', $actionmenu, false, $container);
|
|
|
172 |
$this->execute('behat_general::should_not_exist_in_the', [
|
|
|
173 |
$item, 'link',
|
|
|
174 |
$menu, 'NodeElement'
|
|
|
175 |
]);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
/**
|
|
|
180 |
* The action menu item should exist.
|
|
|
181 |
*
|
|
|
182 |
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu$/
|
|
|
183 |
* @param string $item The item to check
|
|
|
184 |
* @param string $actionmenu The text used in the description of the action menu
|
|
|
185 |
*/
|
|
|
186 |
public function item_should_exist(string $item, string $actionmenu): void {
|
|
|
187 |
$menu = $this->find('actionmenu', $actionmenu);
|
|
|
188 |
$this->execute('behat_general::should_exist_in_the', [
|
|
|
189 |
$item, 'link',
|
|
|
190 |
$menu, 'NodeElement'
|
|
|
191 |
]);
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
/**
|
|
|
195 |
* The action menu item should exist within a container.
|
|
|
196 |
*
|
|
|
197 |
* @Then /^the "(?P<item_string>(?:[^"]|\\")*)" item should exist in the "(?P<actionmenu_string>(?:[^"]|\\")*)" action menu of the "(?P<locator_string>(?:[^"]|\\")*)" "(?P<type_string>(?:[^"]|\\")*)"$/
|
|
|
198 |
* @param string $item The item to check
|
|
|
199 |
* @param string $actionmenu The text used in the description of the action menu
|
|
|
200 |
* @param string|NodeElement $locator The identifer used for the container
|
|
|
201 |
* @param string $selector The type of container to locate
|
|
|
202 |
*/
|
|
|
203 |
public function item_should_exist_in_the(string $item, string $actionmenu, $locator, $selector): void {
|
|
|
204 |
$container = $this->find($selector, $locator);
|
|
|
205 |
$menu = $this->find('actionmenu', $actionmenu, false, $container);
|
|
|
206 |
$this->execute('behat_general::should_exist_in_the', [
|
|
|
207 |
$item, 'link',
|
|
|
208 |
$menu, 'NodeElement'
|
|
|
209 |
]);
|
|
|
210 |
}
|
|
|
211 |
}
|