MDL-64665 core_message: New step to open settings preferences
[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(
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 );
92
93 $this->execute('behat_general::wait_until_the_page_is_ready');
94 }
95
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) {
65f631c5 103 $this->i_open_messaging();
21c6f11c 104
f074d6f0 105 $this->execute('behat_general::i_click_on', [get_string('search', 'core'), 'field']);
eb9ca848 106
f074d6f0
RW
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 ]
eb9ca848
RT
112 );
113
f074d6f0
RW
114 $this->execute('behat_general::i_click_on', ['[data-action="search"]', 'css_element']);
115
16f91ae1
MN
116 $this->execute('behat_general::wait_until_the_page_is_ready');
117
f05c1013
RW
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',
f074d6f0
RW
121 [
122 $this->escape($userfullname),
123 'link',
124 "[data-region='message-drawer'] [data-region='search-results-container']",
f05c1013 125 "css_element",
f074d6f0 126 ]
f05c1013 127 );
16f91ae1
MN
128
129 $this->execute('behat_general::wait_until_the_page_is_ready');
21c6f11c
DM
130 }
131
16f91ae1
MN
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) {
9741087f 140 $this->i_select_user_in_messaging($userfullname);
16f91ae1
MN
141
142 $this->execute('behat_forms::i_set_the_field_with_xpath_to',
143 array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
144 );
145
f074d6f0
RW
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 );
16f91ae1 154 }
f05c1013
RW
155
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) {
8857c715
DW
163 $this->execute('behat_general::wait_until_the_page_is_ready');
164
f05c1013
RW
165 $this->execute('behat_forms::i_set_the_field_with_xpath_to',
166 array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent))
167 );
168
d624c135 169 $this->execute("behat_forms::press_button", get_string('sendmessage', 'message'));
f05c1013 170 }
65f631c5
AA
171
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 }
188
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 }
2cc03305 203
204 /**
205 * Open the contact menu.
206 *
207 * @Given /^I open contact menu$/
208 */
209 public function i_open_contact_menu() {
994b0064 210 $this->execute('behat_general::wait_until_the_page_is_ready');
211 $this->execute('behat_general::i_click_on_in_the',
2cc03305 212 array(
2cc03305 213 'button',
994b0064 214 'css_element',
215 '[data-region="message-drawer"] [data-region="header-container"]',
2cc03305 216 'css_element',
217 )
218 );
219 }
d624c135
AA
220
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 }
5d011977 235
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 }
21c6f11c 252}