See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]
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 28 require_once (__DIR__ . '/../../../lib/behat/behat_base.php'); 29 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 { 39 40 /** 41 * Return the list of partial named selectors. 42 * 43 * @return array 44 */ 45 public static function get_partial_named_selectors(): array { 46 return [ 47 new behat_component_named_selector('Message', [".//*[@data-conversation-id]//img[%altMatch%]/.."]), 48 new behat_component_named_selector('Message conversation', [ 49 <<<XPATH 50 .//*[@data-region='message-drawer' and contains(., %locator%)]//div[@data-region='content-message-container'] 51 XPATH 52 ], false), 53 new behat_component_named_selector('Message header', [ 54 <<<XPATH 55 .//*[@data-region='message-drawer']//div[@data-region='header-content' and contains(., %locator%)] 56 XPATH 57 ]), 58 new behat_component_named_selector('Message member', [ 59 <<<XPATH 60 .//*[@data-region='message-drawer']//div[@data-region='group-info-content-container'] 61 //div[@class='list-group' and not(contains(@class, 'hidden'))]//*[%core_message/textMatch%] 62 XPATH 63 , <<<XPATH 64 .//*[@data-region='message-drawer']//div[@data-region='group-info-content-container'] 65 //div[@data-region='empty-message-container' and not(contains(@class, 'hidden')) and contains(., %locator%)] 66 XPATH 67 ], false), 68 new behat_component_named_selector('Message tab', [ 69 <<<XPATH 70 .//*[@data-region='message-drawer']//button[@data-toggle='collapse' and contains(string(), %locator%)] 71 XPATH 72 ], false), 73 new behat_component_named_selector('Message list area', [ 74 <<<XPATH 75 .//*[@data-region='message-drawer']//*[contains(@data-region, concat('view-overview-', %locator%))] 76 XPATH 77 ], false), 78 new behat_component_named_selector('Message content', [ 79 <<<XPATH 80 .//*[@data-region='message-drawer']//*[@data-region='message' and @data-message-id and contains(., %locator%)] 81 XPATH 82 ], false), 83 ]; 84 } 85 86 /** 87 * Return a list of the Mink named replacements for the component. 88 * 89 * Named replacements allow you to define parts of an xpath that can be reused multiple times, or in multiple 90 * xpaths. 91 * 92 * This method should return a list of {@link behat_component_named_replacement} and the docs on that class explain 93 * how it works. 94 * 95 * @return behat_component_named_replacement[] 96 */ 97 public static function get_named_replacements(): array { 98 return [ 99 new behat_component_named_replacement('textMatch', 'text()[contains(., %locator%)]'), 100 ]; 101 } 102 103 /** 104 * Open the messaging UI. 105 * 106 * @Given /^I open messaging$/ 107 */ 108 public function i_open_messaging() { 109 // Visit home page and follow messages. 110 $this->execute("behat_general::i_am_on_homepage"); 111 $this->execute("behat_general::i_click_on", [get_string('togglemessagemenu', 'core_message'), 'link']); 112 } 113 114 /** 115 * Open the messaging conversation list. 116 * 117 * @Given /^I open the "(?P<tab_string>(?:[^"]|\\")*)" conversations list/ 118 * @param string $tab 119 */ 120 public function i_open_the_conversations_list(string $tab) { 121 $this->execute('behat_general::i_click_on', [ 122 $this->escape($tab), 123 'core_message > Message tab' 124 ]); 125 } 126 127 /** 128 * Open the messaging UI. 129 * 130 * @Given /^I open messaging information$/ 131 */ 132 public function i_open_messaging_information() { 133 $this->execute('behat_general::i_click_on', ["[data-action='view-group-info']", 'css_element']); 134 } 135 136 /** 137 * View the contact information of a user in the messages ui. 138 * 139 * @Given /^I view the "(?P<user_full_name_string>(?:[^"]|\\")*)" contact in the message area$/ 140 * @param string $userfullname 141 */ 142 public function i_view_contact_in_messages($userfullname) { 143 // Visit home page and follow messages. 144 $this->execute('behat_message::i_select_user_in_messaging', [$userfullname]); 145 146 $this->execute('behat_general::i_click_on_in_the', 147 array( 148 "//a[@data-action='view-contact']", 149 "xpath_element", 150 "//*[@data-region='message-drawer']//div[@data-region='header-container']", 151 "xpath_element", 152 ) 153 ); 154 $this->execute('behat_general::i_click_on_in_the', 155 array( 156 "//img[@title='Picture of ". $this->escape($userfullname) . "']", 157 "xpath_element", 158 "//*[@data-region='message-drawer']//*[@data-region='view-contact']", 159 "xpath_element", 160 ) 161 ); 162 163 $this->execute('behat_general::wait_until_the_page_is_ready'); 164 } 165 166 /** 167 * Select a user in the messaging UI. 168 * 169 * @Given /^I select "(?P<user_full_name_string>(?:[^"]|\\")*)" user in messaging$/ 170 * @param string $userfullname 171 */ 172 public function i_select_user_in_messaging($userfullname) { 173 $this->execute('behat_message::i_open_messaging', []); 174 175 $this->execute('behat_message::i_search_for_string_in_messaging', [$userfullname]); 176 177 // Need to limit the click to the search results because the 'view-contact-profile' elements 178 // can occur in two separate divs on the page. 179 $this->execute('behat_general::i_click_on_in_the', 180 [ 181 $this->escape($userfullname), 182 'link', 183 "[data-region='message-drawer'] [data-region='search-results-container']", 184 "css_element", 185 ] 186 ); 187 188 $this->execute('behat_general::wait_until_the_page_is_ready'); 189 } 190 191 /** 192 * Search for a string using the messaging search. 193 * 194 * @Given /^I search for "(?P<string>(?:[^"]|\\")*)" in messaging$/ 195 * @param string $string the search string. 196 */ 197 public function i_search_for_string_in_messaging($string) { 198 $messagedrawer = $this->find('css', '[data-region="message-drawer"]'); 199 $this->execute('behat_general::i_click_on_in_the', [ 200 get_string('search', 'core'), 'field', 201 $messagedrawer, 'NodeElement' 202 ]); 203 204 $this->execute('behat_forms::i_set_the_field_with_xpath_to', [ 205 "//*[@data-region='message-drawer']//input[@data-region='search-input']", 206 $this->escape($string) 207 ]); 208 209 $this->execute('behat_general::i_click_on_in_the', [ 210 '[data-action="search"]', 'css_element', 211 $messagedrawer, 'NodeElement' 212 ]); 213 214 $this->execute('behat_general::wait_until_the_page_is_ready'); 215 } 216 217 /** 218 * Sends a message to the specified user from the logged user. The user full name should contain the first and last names. 219 * 220 * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message to "(?P<user_full_name_string>(?:[^"]|\\")*)" user$/ 221 * @param string $messagecontent 222 * @param string $userfullname 223 */ 224 public function i_send_message_to_user($messagecontent, $userfullname) { 225 $this->execute('behat_message::i_select_user_in_messaging', [$userfullname]); 226 227 $this->execute('behat_forms::i_set_the_field_with_xpath_to', 228 array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent)) 229 ); 230 231 $this->execute('behat_general::i_click_on_in_the', 232 [ 233 '[data-action="send-message"]', 234 'css_element', 235 "[data-region='message-drawer'] [data-region='footer-container'] [data-region='view-conversation']", 236 "css_element", 237 ] 238 ); 239 } 240 241 /** 242 * Select messages from a user in the messaging ui. 243 * 244 * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message in the message area$/ 245 * @param string $messagecontent 246 */ 247 public function i_send_message_in_the_message_area($messagecontent) { 248 $this->execute('behat_general::wait_until_the_page_is_ready'); 249 250 $this->execute('behat_forms::i_set_the_field_with_xpath_to', 251 array("//textarea[@data-region='send-message-txt']", $this->escape($messagecontent)) 252 ); 253 254 $this->execute("behat_forms::press_button", get_string('sendmessage', 'message')); 255 } 256 257 /** 258 * Navigate back in the messages ui drawer. 259 * 260 * @Given /^I go back in "(?P<parent_element_string>(?:[^"]|\\")*)" message drawer$/ 261 * @param string $parentelement 262 */ 263 public function i_go_back_in_message_drawer($parentelement) { 264 $this->execute('behat_general::i_click_on_in_the', 265 array( 266 'a[data-route-back]', 267 'css_element', 268 '[data-region="'.$this->escape($parentelement).'"]', 269 'css_element', 270 ) 271 ); 272 } 273 274 /** 275 * Select a user in the messaging UI. 276 * 277 * @Given /^I select "(?P<conversation_name_string>(?:[^"]|\\")*)" conversation in messaging$/ 278 * @param string $conversationname 279 */ 280 public function i_select_conversation_in_messaging($conversationname) { 281 $this->execute('behat_general::i_click_on', 282 array( 283 $this->escape($conversationname), 284 'core_message > Message', 285 ) 286 ); 287 } 288 289 /** 290 * Open the contact menu. 291 * 292 * @Given /^I open contact menu$/ 293 */ 294 public function i_open_contact_menu() { 295 $this->execute('behat_general::wait_until_the_page_is_ready'); 296 $this->execute('behat_general::i_click_on_in_the', 297 array( 298 'button', 299 'css_element', 300 '[data-region="message-drawer"] [data-region="header-container"]', 301 'css_element', 302 ) 303 ); 304 } 305 306 /** 307 * Select a user in a specific messaging UI conversations list. 308 * 309 * @Given /^I select "(?P<conv_name_string>(?:[^"]|\\")*)" conversation in the "(?P<list_name_string>(?:[^"]|\\")*)" conversations list$/ 310 * @param string $convname 311 * @param string $listname 312 */ 313 public function i_select_conversation_in_the_conversations_list(string $convname, string $listname) { 314 $xpath = '//*[@data-region="message-drawer"]//div[@data-region="view-overview-'. 315 $this->escape($listname). 316 '"]//*[@data-conversation-id]//img[contains(@alt,"'. 317 $this->escape($convname).'")]'; 318 $this->execute('behat_general::i_click_on', array($xpath, 'xpath_element')); 319 } 320 321 /** 322 * Open the settings preferences. 323 * 324 * @Given /^I open messaging settings preferences$/ 325 */ 326 public function i_open_messaging_settings_preferences() { 327 $this->execute('behat_general::wait_until_the_page_is_ready'); 328 $this->execute('behat_general::i_click_on', 329 array( 330 '//*[@data-region="message-drawer"]//a[@data-route="view-settings"]', 331 'xpath_element', 332 '', 333 '', 334 ) 335 ); 336 } 337 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body