MDL-64665 core_message: New step to open settings preferences
[moodle.git] / message / tests / behat / behat_message.php
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/>.
17 /**
18  * Behat message-related steps definitions.
19  *
20  * @package    core_message
21  * @category   test
22  * @copyright  2013 David MonllaĆ³
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
30 /**
31  * Messaging system steps definitions.
32  *
33  * @package    core_message
34  * @category   test
35  * @copyright  2013 David MonllaĆ³
36  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37  */
38 class behat_message extends behat_base {
40     /**
41      * Open the messaging UI.
42      *
43      * @Given /^I open messaging$/
44      */
45     public function i_open_messaging() {
46         // Visit home page and follow messages.
47         $this->execute("behat_general::i_am_on_homepage");
48         $this->execute("behat_general::i_click_on", [get_string('togglemessagemenu', 'core_message'), 'link']);
49     }
51     /**
52      * Open the messaging conversation list.
53      *
54      * @Given /^I open the "(?P<tab_string>(?:[^"]|\\")*)" conversations list/
55      * @param string $tab
56      */
57     public function i_open_the_conversations_list(string $tab) {
58         $this->execute('behat_general::i_click_on', [
59             $this->escape($tab),
60             'group_message_tab'
61         ]);
62     }
64     /**
65      * Open the messaging UI.
66      *
67      * @Given /^I open messaging information$/
68      */
69     public function i_open_messaging_information() {
70         $this->execute('behat_general::i_click_on', ["[data-action='view-group-info']", 'css_element']);
71     }
73     /**
74      * View the contact information of a user in the messages ui.
75      *
76      * @Given /^I view the "(?P<user_full_name_string>(?:[^"]|\\")*)" contact in the message area$/
77      * @param string $userfullname
78      */
79     public function i_view_contact_in_messages($userfullname) {
80         // Visit home page and follow messages.
81         $this->i_select_user_in_messaging($userfullname);
83         $this->execute('behat_general::i_click_on_in_the',
84             array(
85                 "//button[@data-action='view-contact-profile']
86                 [contains(normalize-space(.), '" . $this->escape($userfullname) . "')]",
87                 'xpath_element',
88                 ".messages-header",
89                 "css_element",
90             )
91         );
93         $this->execute('behat_general::wait_until_the_page_is_ready');
94     }
96     /**
97      * Select a user in the messaging UI.
98      *
99      * @Given /^I select "(?P<user_full_name_string>(?:[^"]|\\")*)" user in messaging$/
100      * @param string $userfullname
101      */
102     public function i_select_user_in_messaging($userfullname) {
103         $this->i_open_messaging();
105         $this->execute('behat_general::i_click_on', [get_string('search', 'core'), 'field']);
107         $this->execute('behat_forms::i_set_the_field_with_xpath_to',
108             [
109                 "//*[@data-region='message-drawer']//input[@data-region='search-input']",
110                 $this->escape($userfullname)
111             ]
112         );
114         $this->execute('behat_general::i_click_on', ['[data-action="search"]', 'css_element']);
116         $this->execute('behat_general::wait_until_the_page_is_ready');
118         // Need to limit the click to the search results because the 'view-contact-profile' elements
119         // can occur in two separate divs on the page.
120         $this->execute('behat_general::i_click_on_in_the',
121             [
122                 $this->escape($userfullname),
123                 'link',
124                 "[data-region='message-drawer'] [data-region='search-results-container']",
125                 "css_element",
126             ]
127         );
129         $this->execute('behat_general::wait_until_the_page_is_ready');
130     }
132     /**
133      * Sends a message to the specified user from the logged user. The user full name should contain the first and last names.
134      *
135      * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message to "(?P<user_full_name_string>(?:[^"]|\\")*)" user$/
136      * @param string $messagecontent
137      * @param string $userfullname
138      */
139     public function i_send_message_to_user($messagecontent, $userfullname) {
140         $this->i_select_user_in_messaging($userfullname);
142         $this->execute('behat_forms::i_set_the_field_with_xpath_to',
143             array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
144         );
146         $this->execute('behat_general::i_click_on_in_the',
147             [
148                 '[data-action="send-message"]',
149                 'css_element',
150                 "[data-region='message-drawer'] [data-region='footer-container'] [data-region='view-conversation']",
151                 "css_element",
152             ]
153         );
154     }
156     /**
157      * Select messages from a user in the messaging ui.
158      *
159      * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message in the message area$/
160      * @param string $messagecontent
161      */
162     public function i_send_message_in_the_message_area($messagecontent) {
163         $this->execute('behat_general::wait_until_the_page_is_ready');
165         $this->execute('behat_forms::i_set_the_field_with_xpath_to',
166             array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
167         );
169         $this->execute("behat_forms::press_button", get_string('sendmessage', 'message'));
170     }
172     /**
173      * Navigate back in the messages ui drawer.
174      *
175      * @Given /^I go back in "(?P<parent_element_string>(?:[^"]|\\")*)" message drawer$/
176      * @param string $parentelement
177      */
178     public function i_go_back_in_message_drawer($parentelement) {
179         $this->execute('behat_general::i_click_on_in_the',
180             array(
181                 'a[data-route-back]',
182                 'css_element',
183                 '[data-region="'.$this->escape($parentelement).'"]',
184                 'css_element',
185             )
186         );
187     }
189     /**
190      * Select a user in the messaging UI.
191      *
192      * @Given /^I select "(?P<conversation_name_string>(?:[^"]|\\")*)" conversation in messaging$/
193      * @param string $conversationname
194      */
195     public function i_select_conversation_in_messaging($conversationname) {
196         $this->execute('behat_general::i_click_on',
197             array(
198                 $this->escape($conversationname),
199                 'group_message',
200             )
201         );
202     }
204     /**
205      * Open the contact menu.
206      *
207      * @Given /^I open contact menu$/
208      */
209     public function i_open_contact_menu() {
210         $this->execute('behat_general::wait_until_the_page_is_ready');
211         $this->execute('behat_general::i_click_on_in_the',
212             array(
213                 'button',
214                 'css_element',
215                 '[data-region="message-drawer"] [data-region="header-container"]',
216                 'css_element',
217             )
218         );
219     }
221     /**
222      * Select a user in a specific messaging UI conversations list.
223      *
224      * @Given /^I select "(?P<conv_name_string>(?:[^"]|\\")*)" conversation in the "(?P<list_name_string>(?:[^"]|\\")*)" conversations list$/
225      * @param string $convname
226      * @param string $listname
227      */
228     public function i_select_conversation_in_the_conversations_list(string $convname, string $listname) {
229         $xpath = '//*[@data-region="message-drawer"]//div[@data-region="view-overview-'.
230             $this->escape($listname).
231             '"]//*[@data-conversation-id]//img[contains(@alt,"'.
232             $this->escape($convname).'")]';
233         $this->execute('behat_general::i_click_on', array($xpath, 'xpath_element'));
234     }
236     /**
237      * Open the settings preferences.
238      *
239      * @Given /^I open messaging settings preferences$/
240      */
241     public function i_open_messaging_settings_preferences() {
242         $this->execute('behat_general::wait_until_the_page_is_ready');
243         $this->execute('behat_general::i_click_on',
244             array(
245                 '//*[@data-region="message-drawer"]//a[@data-route="view-settings"]',
246                 'xpath_element',
247                 '',
248                 '',
249             )
250         );
251     }