Merge branch 'MDL-64665-master' of git://github.com/cescobedo/moodle
[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                 "//a[@data-action='view-contact']",
86                 "xpath_element",
87                 "//*[@data-region='message-drawer']//div[@data-region='header-container']",
88                 "xpath_element",
89             )
90         );
91         $this->execute('behat_general::i_click_on_in_the',
92             array(
93                 $this->escape($userfullname),
94                 "link",
95                 "//*[@data-region='message-drawer']//*[@data-region='view-contact']",
96                 "xpath_element",
97             )
98         );
100         $this->execute('behat_general::wait_until_the_page_is_ready');
101     }
103     /**
104      * Select a user in the messaging UI.
105      *
106      * @Given /^I select "(?P<user_full_name_string>(?:[^"]|\\")*)" user in messaging$/
107      * @param string $userfullname
108      */
109     public function i_select_user_in_messaging($userfullname) {
110         $this->i_open_messaging();
112         $this->execute('behat_general::i_click_on', [get_string('search', 'core'), 'field']);
114         $this->execute('behat_forms::i_set_the_field_with_xpath_to',
115             [
116                 "//*[@data-region='message-drawer']//input[@data-region='search-input']",
117                 $this->escape($userfullname)
118             ]
119         );
121         $this->execute('behat_general::i_click_on', ['[data-action="search"]', 'css_element']);
123         $this->execute('behat_general::wait_until_the_page_is_ready');
125         // Need to limit the click to the search results because the 'view-contact-profile' elements
126         // can occur in two separate divs on the page.
127         $this->execute('behat_general::i_click_on_in_the',
128             [
129                 $this->escape($userfullname),
130                 'link',
131                 "[data-region='message-drawer'] [data-region='search-results-container']",
132                 "css_element",
133             ]
134         );
136         $this->execute('behat_general::wait_until_the_page_is_ready');
137     }
139     /**
140      * Sends a message to the specified user from the logged user. The user full name should contain the first and last names.
141      *
142      * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message to "(?P<user_full_name_string>(?:[^"]|\\")*)" user$/
143      * @param string $messagecontent
144      * @param string $userfullname
145      */
146     public function i_send_message_to_user($messagecontent, $userfullname) {
147         $this->i_select_user_in_messaging($userfullname);
149         $this->execute('behat_forms::i_set_the_field_with_xpath_to',
150             array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
151         );
153         $this->execute('behat_general::i_click_on_in_the',
154             [
155                 '[data-action="send-message"]',
156                 'css_element',
157                 "[data-region='message-drawer'] [data-region='footer-container'] [data-region='view-conversation']",
158                 "css_element",
159             ]
160         );
161     }
163     /**
164      * Select messages from a user in the messaging ui.
165      *
166      * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message in the message area$/
167      * @param string $messagecontent
168      */
169     public function i_send_message_in_the_message_area($messagecontent) {
170         $this->execute('behat_general::wait_until_the_page_is_ready');
172         $this->execute('behat_forms::i_set_the_field_with_xpath_to',
173             array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
174         );
176         $this->execute("behat_forms::press_button", get_string('sendmessage', 'message'));
177     }
179     /**
180      * Navigate back in the messages ui drawer.
181      *
182      * @Given /^I go back in "(?P<parent_element_string>(?:[^"]|\\")*)" message drawer$/
183      * @param string $parentelement
184      */
185     public function i_go_back_in_message_drawer($parentelement) {
186         $this->execute('behat_general::i_click_on_in_the',
187             array(
188                 'a[data-route-back]',
189                 'css_element',
190                 '[data-region="'.$this->escape($parentelement).'"]',
191                 'css_element',
192             )
193         );
194     }
196     /**
197      * Select a user in the messaging UI.
198      *
199      * @Given /^I select "(?P<conversation_name_string>(?:[^"]|\\")*)" conversation in messaging$/
200      * @param string $conversationname
201      */
202     public function i_select_conversation_in_messaging($conversationname) {
203         $this->execute('behat_general::i_click_on',
204             array(
205                 $this->escape($conversationname),
206                 'group_message',
207             )
208         );
209     }
211     /**
212      * Open the contact menu.
213      *
214      * @Given /^I open contact menu$/
215      */
216     public function i_open_contact_menu() {
217         $this->execute('behat_general::wait_until_the_page_is_ready');
218         $this->execute('behat_general::i_click_on_in_the',
219             array(
220                 'button',
221                 'css_element',
222                 '[data-region="message-drawer"] [data-region="header-container"]',
223                 'css_element',
224             )
225         );
226     }
228     /**
229      * Select a user in a specific messaging UI conversations list.
230      *
231      * @Given /^I select "(?P<conv_name_string>(?:[^"]|\\")*)" conversation in the "(?P<list_name_string>(?:[^"]|\\")*)" conversations list$/
232      * @param string $convname
233      * @param string $listname
234      */
235     public function i_select_conversation_in_the_conversations_list(string $convname, string $listname) {
236         $xpath = '//*[@data-region="message-drawer"]//div[@data-region="view-overview-'.
237             $this->escape($listname).
238             '"]//*[@data-conversation-id]//img[contains(@alt,"'.
239             $this->escape($convname).'")]';
240         $this->execute('behat_general::i_click_on', array($xpath, 'xpath_element'));
241     }
243     /**
244      * Open the settings preferences.
245      *
246      * @Given /^I open messaging settings preferences$/
247      */
248     public function i_open_messaging_settings_preferences() {
249         $this->execute('behat_general::wait_until_the_page_is_ready');
250         $this->execute('behat_general::i_click_on',
251             array(
252                 '//*[@data-region="message-drawer"]//a[@data-route="view-settings"]',
253                 'xpath_element',
254                 '',
255                 '',
256             )
257         );
258     }