-
Notifications
You must be signed in to change notification settings - Fork 60
/
behat_theme_boost_union_behat_smartmenus.php
257 lines (224 loc) · 11.6 KB
/
behat_theme_boost_union_behat_smartmenus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Theme Boost Union - Custom Behat rules for smartmenus
*
* @package theme_boost_union
* @copyright 2023 bdecent GmbH <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../../../lib/behat/behat_base.php');
use Behat\Gherkin\Node\{TableNode, PyStringNode};
/**
* Class behat_theme_boost_union_behat_smartmenus
*
* @package theme_boost_union
* @copyright 2023 bdecent GmbH <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_theme_boost_union_behat_smartmenus extends behat_base {
/**
* Open the smart menu listing page.
*
* @Given /^I navigate to smartmenus$/
*
*/
public function i_navigate_to_smartmenus() {
$this->execute('behat_navigation::i_navigate_to_in_site_administration',
["Appearance > Themes > Boost Union > Smart menus"]);
}
/**
* Open the smart menu items listing page.
*
* @Given /^I navigate to smartmenu "(?P<menuname>(?:[^"]|\\")*)" items$/
*
* @param string $menu Menu title.
*/
public function i_navigate_to_smartmenu_item($menu) {
$this->execute('behat_navigation::i_navigate_to_in_site_administration',
["Appearance > Themes > Boost Union > Smart menus"]);
$this->execute("behat_general::i_click_on_in_the", ['.action-list-items', "css_element", $menu, 'table_row']);
}
/**
* Fills a smart menu create form with field/value data.
*
* @Given /^I create menu with the following fields to these values:$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param TableNode $data
*/
public function i_create_menu_with_the_following_fields_to_these_values(TableNode $data) {
$this->execute('behat_navigation::i_navigate_to_in_site_administration',
["Appearance > Themes > Boost Union > Smart menus"]);
$this->execute("behat_general::i_click_on", ["Create new smart menu", "button"]);
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$data]);
$this->execute("behat_general::i_click_on", ["Save and return", "button"]);
}
/**
* Fills a smart menu item form with field/value data.
*
* @Given /^I set "(?P<menuname>(?:[^"]|\\")*)" items with the following fields to these values:$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $menu Menu title.
* @param TableNode $data
*/
public function i_create_menus_with_the_following_fields_to_these_values($menu, TableNode $data) {
$this->execute('behat_navigation::i_navigate_to_in_site_administration',
["Appearance > Themes > Boost Union > Smart menus"]);
$this->execute("behat_general::i_click_on_in_the", [".action-list-items", "css_element", $menu, 'table_row']);
$this->execute("behat_general::i_click_on", ["Add new menu item", "button"]);
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$data]);
$this->execute("behat_general::i_click_on", ["Save changes", "button"]);
}
/**
* Verify the card size height.
*
* @Given /^I should see "(?P<element>(?:[^"]|\\")*)" style "(?P<rule>(?:[^"]|\\")*)" value "(?P<value>(?:[^"]|\\")*)"$/
* @param string $selector
* @param string $rule
* @param string $value
*/
public function i_should_see_style_value($selector, $rule, $value) {
// The DOM and the JS should be all ready and loaded. Running without spinning
// as this is a widely used step and we can not spend time here trying to see
// a DOM node that is not always there (at the moment clean is not even the
// default theme...).
$navbuttonjs = "return (
Y.one('$selector') &&
Y.one('$selector').getComputedStyle('$rule') !== $value
)";
// Adding an extra click we need to show the 'Log in' link.
if (!$this->evaluate_script($navbuttonjs)) {
return false;
}
return true;
}
/**
* Test the menus are avaialble and visible in the given locations.
*
* @Given /^I should see menu "(?P<menu>(?:[^"]|\\")*)" in location "(?P<locations>(?:[^"]|\\")*)"$/
*
* @param string $menu Menu title.
* @param string $locations Menu locations to verify (Main, Menu, User, Bottom)
*/
public function i_should_see_menu_in_location($menu, $locations) {
$locations = array_map('trim', explode(',', $locations));
if (in_array('Main', $locations)) {
$this->execute('behat_general::assert_element_contains_text', [$menu, ".primary-navigation", "css_element"]);
}
if (in_array('User', $locations)) {
$this->execute('behat_general::i_click_on', ["#user-menu-toggle", "css_element"]);
$this->execute('behat_general::assert_element_contains_text', [$menu, "#user-action-menu", "css_element"]);
}
if (in_array('Bottom', $locations)) {
$this->execute('behat_general::i_change_window_size_to', ['viewport', '750x1000']);
$this->execute('behat_general::assert_element_contains_text', [$menu, ".boost-union-bottom-menu", "css_element"]);
$this->execute('behat_general::i_change_window_size_to', ['viewport', 'large']);
}
if (in_array('Menu', $locations)) {
$this->execute('behat_general::assert_element_contains_text', [$menu, ".boost-union-menubar", "css_element"]);
}
}
/**
* Test the menu items are avaialble and visible in the given locations.
*
* @Given I should see menu :menu item :item in location :locations
*
* @param string $menu Menu title
* @param string $item Menu item title
* @param string $locations Locations to verify (Main, Menu, Bottom, User)
*/
public function i_should_see_menu_item_in_location($menu, $item, $locations) {
$locations = array_map('trim', explode(',', $locations));
if (in_array('Main', $locations)) {
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", ".primary-navigation", "css_element"]);
$this->execute('behat_general::assert_element_contains_text', [$item, ".primary-navigation", "css_element"]);
}
if (in_array('User', $locations)) {
$this->execute('behat_general::i_click_on', ["#user-menu-toggle", "css_element"]);
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", "#usermenu-carousel", "css_element"]);
$this->execute('behat_general::assert_element_contains_text', [$item, ".carousel-item.active", "css_element"]);
$this->execute('behat_general::i_click_on', ["#user-menu-toggle", "css_element"]);
}
if (in_array('Bottom', $locations)) {
$this->execute('behat_general::i_change_window_size_to', ['viewport', '750x900']);
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", ".bottom-navigation", "css_element"]);
$this->execute('behat_general::assert_element_contains_text', [$item, ".bottom-navigation", "css_element"]);
$this->execute('behat_general::i_change_window_size_to', ['viewport', 'large']);
}
if (in_array('Menu', $locations)) {
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", "nav.menubar", "css_element"]);
$this->execute('behat_general::assert_element_contains_text', [$item, ".boost-union-menubar", "css_element"]);
}
}
/**
* Test the menus are not avaialble or visible in the given locations.
*
* @Given I should not see menu :menu in location :location
*
* @param string $menu Menu title
* @param string $location Locations to verify (Main, Menu, Bottom, User)
*/
public function i_should_not_see_menu_in_location($menu, $location) {
$locations = array_map('trim', explode(',', $location));
if (in_array('Main', $locations)) {
$this->execute('behat_general::assert_element_not_contains_text', [$menu, ".primary-navigation", "css_element"]);
}
if (in_array('User', $locations)) {
$this->execute('behat_general::i_click_on', ["#user-menu-toggle", "css_element"]);
$this->execute('behat_general::assert_element_not_contains_text', [$menu, "#user-action-menu", "css_element"]);
}
if (in_array('Bottom', $locations)) {
$this->execute('behat_general::i_change_window_size_to', ['viewport', '750x900']);
$this->execute('behat_general::assert_element_not_contains_text', [$menu, ".boost-union-bottom-menu", "css_element"]);
$this->execute('behat_general::i_change_window_size_to', ['viewport', 'large']);
}
if (in_array('Menu', $locations)) {
$this->execute('behat_general::assert_element_not_contains_text', [$menu, ".boost-union-menubar", "css_element"]);
}
}
/**
* Test the menu items are not avaialble and visible in the given locations.
*
* @Given I should not see menu :menu item :item in location :location
*
* @param string $menu Menu title
* @param string $item Menu item title
* @param string $location Locations to verify (Main, Menu, Bottom, User)
*/
public function i_should_not_see_menu_item_in_location($menu, $item, $location) {
$locations = array_map('trim', explode(',', $location));
if (in_array('Main', $locations)) {
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", ".primary-navigation", "css_element"]);
$this->execute('behat_general::assert_element_not_contains_text', [$item, ".primary-navigation", "css_element"]);
}
if (in_array('User', $locations)) {
$this->execute('behat_general::i_click_on', ["#user-menu-toggle", "css_element"]);
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", "#usermenu-carousel", "css_element"]);
$this->execute('behat_general::assert_element_not_contains_text', [$item, ".carousel-item.active", "css_element"]);
$this->execute('behat_general::i_click_on', ["#user-menu-toggle", "css_element"]);
}
if (in_array('Bottom', $locations)) {
$this->execute('behat_general::i_change_window_size_to', ['viewport', '750x900']);
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", ".bottom-navigation", "css_element"]);
$this->execute('behat_general::assert_element_not_contains_text', [$item, ".boost-union-bottom-menu", "css_element"]);
$this->execute('behat_general::i_change_window_size_to', ['viewport', 'large']);
}
if (in_array('Menu', $locations)) {
$this->execute('behat_general::i_click_on_in_the', [$menu, "link", "nav.menubar", "css_element"]);
$this->execute('behat_general::assert_element_not_contains_text', [$item, ".boost-union-menubar", "css_element"]);
}
}
}