Merge branch 'MDL-64676-master-fix' of https://github.com/snake/moodle
[moodle.git] / message / tests / behat / behat_message.php
CommitLineData
21c6f11c
DM
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 * 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 */
25
26// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
27
28require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
29
21c6f11c
DM
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 */
38class behat_message extends behat_base {
39
65f631c5
AA
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 }
50
d624c135
AA
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 }
63
65f631c5
AA
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 }
72
21c6f11c 73 /**
f05c1013 74 * View the contact information of a user in the messages ui.
21c6f11c 75 *
f05c1013 76 * @Given /^I view the "(?P<user_full_name_string>(?:[^"]|\\")*)" contact in the message area$/
14ebd163 77 * @param string $userfullname
21c6f11c 78 */
f05c1013 79 public function i_view_contact_in_messages($userfullname) {
9741087f
DW
80 // Visit home page and follow messages.
81 $this->i_select_user_in_messaging($userfullname);
82
83 $this->execute('behat_general::i_click_on_in_the',
84 array(
06b02810
AA
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(
ca264ee6
JD
93 "//img[@title='Picture of ". $this->escape($userfullname) . "']",
94 "xpath_element",
06b02810
AA
95 "//*[@data-region='message-drawer']//*[@data-region='view-contact']",
96 "xpath_element",
9741087f
DW
97 )
98 );
99
100 $this->execute('behat_general::wait_until_the_page_is_ready');
101 }
102
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) {
65f631c5 110 $this->i_open_messaging();
21c6f11c 111
f074d6f0 112 $this->execute('behat_general::i_click_on', [get_string('search', 'core'), 'field']);
eb9ca848 113
f074d6f0
RW
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 ]
eb9ca848
RT
119 );
120
f074d6f0
RW
121 $this->execute('behat_general::i_click_on', ['[data-action="search"]', 'css_element']);
122
16f91ae1
MN
123 $this->execute('behat_general::wait_until_the_page_is_ready');
124
f05c1013
RW
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',
f074d6f0
RW
128 [
129 $this->escape($userfullname),
130 'link',
131 "[data-region='message-drawer'] [data-region='search-results-container']",
f05c1013 132 "css_element",
f074d6f0 133 ]
f05c1013 134 );
16f91ae1
MN
135
136 $this->execute('behat_general::wait_until_the_page_is_ready');
21c6f11c
DM
137 }
138
16f91ae1
MN
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) {
9741087f 147 $this->i_select_user_in_messaging($userfullname);
16f91ae1
MN
148
149 $this->execute('behat_forms::i_set_the_field_with_xpath_to',
150 array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
151 );
152
f074d6f0
RW
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 );
16f91ae1 161 }
f05c1013
RW
162
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) {
8857c715
DW
170 $this->execute('behat_general::wait_until_the_page_is_ready');
171
f05c1013
RW
172 $this->execute('behat_forms::i_set_the_field_with_xpath_to',
173 array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
174 );
175
d624c135 176 $this->execute("behat_forms::press_button", get_string('sendmessage', 'message'));
f05c1013 177 }
65f631c5
AA
178
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 }
195
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 }
2cc03305 210
211 /**
212 * Open the contact menu.
213 *
214 * @Given /^I open contact menu$/
215 */
216 public function i_open_contact_menu() {
994b0064 217 $this->execute('behat_general::wait_until_the_page_is_ready');
218 $this->execute('behat_general::i_click_on_in_the',
2cc03305 219 array(
2cc03305 220 'button',
994b0064 221 'css_element',
222 '[data-region="message-drawer"] [data-region="header-container"]',
2cc03305 223 'css_element',
224 )
225 );
226 }
d624c135
AA
227
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 }
5d011977 242
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 }
21c6f11c 259}