Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
18
 
19
require_once(__DIR__ . '/../../../../lib/behat/behat_deprecated_base.php');
20
 
21
use Behat\Mink\Element\NodeElement;
22
use Behat\Mink\Exception\ExpectationException as ExpectationException;
23
use Behat\Mink\Exception\DriverException as DriverException;
24
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
25
 
26
/**
27
 * Behat steps in plugin block_social_activities
28
 *
29
 * @package    block_social_activities
30
 * @category   test
31
 * @copyright  2024 Ferran Recio <ferran@moodle.com>
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class behat_block_social_activities_deprecated extends behat_deprecated_base {
35
    /**
36
     * Returns the DOM node of the activity in the social activities block
37
     *
38
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
39
     * @throws ElementNotFoundException Thrown by behat_base::find
40
     * @param string $activityname The activity name
41
     * @return NodeElement
42
     */
43
    protected function get_social_block_activity_node($activityname) {
44
        $activityname = behat_context_helper::escape($activityname);
45
        $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]";
46
 
47
        return $this->find('xpath', $xpath);
48
    }
49
 
50
    /**
51
     * Finds the element containing a specific activity in the social activity block.
52
     *
53
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
54
     * @throws ElementNotFoundException
55
     * @param string $element
56
     * @param string $selectortype
57
     * @param string $activityname
58
     * @return NodeElement
59
     */
60
    protected function get_social_block_activity_element($element, $selectortype, $activityname) {
61
        $activitynode = $this->get_social_block_activity_node($activityname);
62
 
63
        $exception = new ElementNotFoundException($this->getSession(), "'{$element}' '{$selectortype}' in '{$activityname}'");
64
        return $this->find($selectortype, $element, $exception, $activitynode);
65
    }
66
 
67
    /**
68
     * Checks that the specified activity in the social activities block should have the specified editing icon.
69
     *
70
     * This includes items in the action menu for the item (does not require it to be open)
71
     *
72
     * You should be in the course page with editing mode turned on.
73
     *
74
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
75
     * @deprecated since 5.0
76
     *
77
     * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should have "(?P<icon_name_string>(?:[^"]|\\")*)" editing icon$/
78
     * @param string $activityname
79
     * @param string $iconname
80
     */
81
    public function activity_in_social_activities_block_should_have_editing_icon($activityname, $iconname) {
82
        $this->deprecated_message([
83
            'behat_block_social_activities::activity_in_social_activities_block_should_have_editing_icon is deprecated',
84
            'Use: I should see WHATEVER in the ACTIVITYNAME "activity"',
85
        ]);
86
 
87
        $activitynode = $this->get_social_block_activity_node($activityname);
88
 
89
        $notfoundexception = new ExpectationException('"' . $activityname . '" doesn\'t have a "' .
90
            $iconname . '" editing icon', $this->getSession());
91
        $this->find('named_partial', ['link', $iconname], $notfoundexception, $activitynode);
92
    }
93
 
94
    /**
95
     * Checks that the specified activity in the social activities block should not have the specified editing icon.
96
     *
97
     * This includes items in the action menu for the item (does not require it to be open)
98
     *
99
     * You should be in the course page with editing mode turned on.
100
     *
101
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
102
     * @deprecated since 5.0
103
     *
104
     * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should not have "(?P<icon_name_string>(?:[^"]|\\")*)" editing icon$/
105
     * @param string $activityname
106
     * @param string $iconname
107
     */
108
    public function activity_in_social_activities_block_should_not_have_editing_icon($activityname, $iconname) {
109
        $this->deprecated_message([
110
            'behat_block_social_activities::activity_in_social_activities_block_should_not_have_editing_icon is deprecated',
111
            'Use: I should not see WHATEVER in the ACTIVITYNAME "activity"',
112
        ]);
113
 
114
        $activitynode = $this->get_social_block_activity_node($activityname);
115
 
116
        try {
117
            $this->find('named_partial', ['link', $iconname], false, $activitynode);
118
            throw new ExpectationException('"' . $activityname . '" has a "' . $iconname .
119
                '" editing icon when it should not', $this->getSession());
120
        } catch (ElementNotFoundException $e) {
121
            // This is good, the menu item should not be there.
122
            return;
123
        }
124
    }
125
 
126
    /**
127
     * Clicks on the specified element of the activity. You should be in the course page with editing mode turned on.
128
     *
129
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
130
     * @deprecated since 5.0
131
     *
132
     * @Given /^I click on "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" in the "(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block$/
133
     * @param string $element
134
     * @param string $selectortype
135
     * @param string $activityname
136
     */
137
    public function i_click_on_in_the_activity_in_social_activities_block($element, $selectortype, $activityname) {
138
        $this->deprecated_message([
139
            'behat_block_social_activities::i_click_on_in_the_activity_in_social_activities_block is deprecated',
140
            'Use: I open ACTIVITYNAME actions menu & I choose OPTIONTEXT in the open action menu',
141
        ]);
142
 
143
        $element = $this->get_social_block_activity_element($element, $selectortype, $activityname);
144
        $element->click();
145
    }
146
 
147
    /**
148
     * Checks that the specified activity is hidden in the social activities block.
149
     *
150
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
151
     * @deprecated since 5.0
152
     *
153
     * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should be hidden$/
154
     * @param string $activityname
155
     */
156
    public function activity_in_social_activities_block_should_be_hidden($activityname) {
157
        $this->deprecated_message([
158
            'behat_block_social_activities::activity_in_social_activities_block_should_be_hidden is deprecated',
159
            'Use: I should see "Hidden from students" in the "ACTIVITYNAME" "core_courseformat > Activity visibility"',
160
        ]);
161
 
162
        $activitynode = $this->get_social_block_activity_node($activityname);
163
        $exception = new ExpectationException('"' . $activityname . '" is not hidden', $this->getSession());
164
        $this->find('named_partial', ['badge', get_string('hiddenfromstudents')], $exception, $activitynode);
165
    }
166
 
167
    /**
168
     * Checks that the specified activity is hidden in the social activities block.
169
     *
170
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
171
     * @deprecated since 5.0
172
     *
173
     * @Then /^"(?P<activity_name_string>(?:[^"]|\\")*)" activity in social activities block should be available but hidden from course page$/
174
     * @param string $activityname
175
     */
176
    public function activity_in_social_activities_block_should_be_available_but_hidden_from_course_page($activityname) {
177
        $this->deprecated_message([
178
            'behat_block_social_activities::activity_in_social_activities_block_should_be_available_but_hidden_from_course_page is deprecated',
179
            'Use: I should see "Available but not shown on course page" in the "ACTIVITYNAME" "core_courseformat > Activity visibility"',
180
        ]);
181
 
182
        $activitynode = $this->get_social_block_activity_node($activityname);
183
        $exception = new ExpectationException('"' . $activityname . '" is not hidden but available', $this->getSession());
184
        $this->find('named_partial', ['badge', get_string('hiddenoncoursepage')], $exception, $activitynode);
185
    }
186
 
187
    /**
188
     * Opens an activity actions menu in the social activities block if it is not already opened.
189
     *
190
     * @todo MDL-78077 This will be deleted in Moodle 6.0.
191
     * @deprecated since 5.0
192
     *
193
     * @Given /^I open "(?P<activity_name_string>(?:[^"]|\\")*)" actions menu in social activities block$/
194
     * @throws DriverException The step is not available when Javascript is disabled
195
     * @param string $activityname
196
     */
197
    public function i_open_actions_menu_in_social_activities_block($activityname) {
198
        $this->deprecated_message([
199
            'behat_block_social_activities::i_open_actions_menu_in_social_activities_block is deprecated',
200
            'Use: I open "ACTIVITYNAME" actions menu',
201
        ]);
202
 
203
        $activityname = behat_context_helper::escape($activityname);
204
        $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]";
205
        $this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']);
206
    }
207
}