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 |
* Custom behat step definitions.
|
|
|
19 |
*
|
|
|
20 |
* @package block_dash
|
|
|
21 |
* @copyright 2022 bdecent gmbh <https://bdecent.de>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
|
|
|
26 |
|
|
|
27 |
use Behat\Gherkin\Node\TableNode as TableNode,
|
|
|
28 |
Behat\Mink\Exception\DriverException as DriverException,
|
|
|
29 |
Behat\Mink\Exception\ExpectationException as ExpectationException;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Custom behat step definitions.
|
|
|
33 |
*/
|
|
|
34 |
class behat_block_dash extends behat_base {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Turns block editing mode on.
|
|
|
38 |
*
|
|
|
39 |
* @Given I turn dash block editing mode on
|
|
|
40 |
*/
|
|
|
41 |
public function i_turn_dash_block_editing_mode_on() {
|
|
|
42 |
global $CFG;
|
|
|
43 |
|
|
|
44 |
if ($CFG->branch >= "400") {
|
|
|
45 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('editmode'), 1]);
|
|
|
46 |
if (!$this->running_javascript()) {
|
|
|
47 |
$this->execute('behat_general::i_click_on', [
|
|
|
48 |
get_string('setmode', 'core'),
|
|
|
49 |
'button',
|
|
|
50 |
]);
|
|
|
51 |
}
|
|
|
52 |
} else {
|
|
|
53 |
$this->execute('behat_general::i_click_on', ['Blocks editing on', 'button']);
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* I follow badge recipients
|
|
|
59 |
* @Given I follow badge recipients
|
|
|
60 |
*/
|
|
|
61 |
public function i_follow_badge_recipients() {
|
|
|
62 |
global $CFG;
|
|
|
63 |
|
|
|
64 |
if ($CFG->branch >= "400") {
|
|
|
65 |
$this->execute('behat_forms::i_select_from_the_singleselect', ["Recipients (0)", "jump"]);
|
|
|
66 |
} else {
|
|
|
67 |
$this->execute('behat_general::i_click_on', ["Recipients (0)", "link"]);
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* I follow dashboard
|
|
|
73 |
* @Given I follow dashboard
|
|
|
74 |
*/
|
|
|
75 |
public function i_follow_dashboard() {
|
|
|
76 |
global $CFG;
|
|
|
77 |
|
|
|
78 |
if ($CFG->branch >= "400") {
|
|
|
79 |
$this->execute('behat_general::i_click_on', ["Dashboard", 'link']);
|
|
|
80 |
} else {
|
|
|
81 |
$this->execute('behat_navigation::i_follow_in_the_user_menu', ["Dashboard"]);
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Creates a datasource for dash block.
|
|
|
87 |
*
|
|
|
88 |
* @Given I create dash :arg1 datasource
|
|
|
89 |
*
|
|
|
90 |
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
|
91 |
* @param string $datasource
|
|
|
92 |
*/
|
|
|
93 |
public function i_create_dash_datasource($datasource) {
|
|
|
94 |
global $CFG;
|
|
|
95 |
|
|
|
96 |
$this->execute('behat_navigation::i_navigate_to_in_site_administration',
|
|
|
97 |
['Appearance > Default Dashboard page']);
|
|
|
98 |
$this->execute('behat_block_dash::i_turn_dash_block_editing_mode_on', []);
|
|
|
99 |
$this->execute('behat_blocks::i_add_the_block', ["Dash"]);
|
|
|
100 |
$this->execute('behat_general::i_click_on_in_the', [$datasource, 'text', 'New Dash', 'block']);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Clicks on preference of the dash for specified block. Page must be in editing mode.
|
|
|
105 |
*
|
|
|
106 |
* Argument block_name may be either the name of the block or CSS class of the block.
|
|
|
107 |
*
|
|
|
108 |
* @Given /^I open the "(?P<block_name_string>(?:[^"]|\\")*)" block preference$/
|
|
|
109 |
* @param string $blockname
|
|
|
110 |
*/
|
|
|
111 |
public function i_open_the_dash_block($blockname) {
|
|
|
112 |
// Note that since $blockname may be either block name or CSS class, we can not use the exact label of "Configure" link.
|
|
|
113 |
$this->execute("behat_blocks::i_open_the_blocks_action_menu", $this->escape($blockname));
|
|
|
114 |
|
|
|
115 |
$this->execute('behat_general::i_click_on_in_the',
|
|
|
116 |
["Preference", "link", $this->escape($blockname), "block"]
|
|
|
117 |
);
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* Check that the focus mode enable.
|
|
|
122 |
*
|
|
|
123 |
* @Given /^I check dash css "(?P<value>(?:[^"]|\\")*)" "(?P<selector>(?:[^"]|\\")*)" "(?P<type>(?:[^"]|\\")*)"$/
|
|
|
124 |
* @param string $value
|
|
|
125 |
* @param string $selector
|
|
|
126 |
* @param string $type
|
|
|
127 |
* @throws ExpectationException
|
|
|
128 |
*/
|
|
|
129 |
public function i_check_dash_css($value, $selector, $type): void {
|
|
|
130 |
$stylejs = "
|
|
|
131 |
return (
|
|
|
132 |
Y.one('{$selector}').getComputedStyle('{$type}')
|
|
|
133 |
)
|
|
|
134 |
";
|
|
|
135 |
if (strpos($this->evaluate_script($stylejs), $value) === false) {
|
|
|
136 |
throw new ExpectationException("Doesn't working correct style", $this->getSession());
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
}
|