From cbf62420e0844992c665be074a00cc9463434289 Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 13 Mar 2019 01:07:06 +0100 Subject: [PATCH 1/4] MDL-64664 core_message: New step for open contact menu --- message/tests/behat/behat_message.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/message/tests/behat/behat_message.php b/message/tests/behat/behat_message.php index 41e172268ec..f836def56f7 100644 --- a/message/tests/behat/behat_message.php +++ b/message/tests/behat/behat_message.php @@ -187,4 +187,20 @@ class behat_message extends behat_base { ) ); } + + /** + * Open the contact menu. + * + * @Given /^I open contact menu$/ + */ + public function i_open_contact_menu() { + $this->execute('behat_general::i_click_on_in_the', + array( + '', + 'button', + '[data-region="header-container"]', + 'css_element', + ) + ); + } } From d940ccbe0be56bac6cff27e8fb4290ea1f07e963 Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 13 Mar 2019 01:14:56 +0100 Subject: [PATCH 2/4] MDL-64664 core_message: New data generator for contacts --- lib/tests/behat/behat_data_generators.php | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/tests/behat/behat_data_generators.php b/lib/tests/behat/behat_data_generators.php index d0bdb8eee7c..2577d462f4a 100644 --- a/lib/tests/behat/behat_data_generators.php +++ b/lib/tests/behat/behat_data_generators.php @@ -183,6 +183,11 @@ class behat_data_generators extends behat_base { 'category' => 'categoryid', ) ), + 'message contacts' => array( + 'datagenerator' => 'message_contacts', + 'required' => array('user', 'contact'), + 'switchids' => array('user' => 'userid', 'contact' => 'contactid') + ), ); /** @@ -837,4 +842,28 @@ class behat_data_generators extends behat_base { return $context; } + /** + * Adds user to contacts + * + * @param array $data + * @return void + */ + protected function process_message_contacts($data) { + \core_message\api::add_contact($data['userid'], $data['contactid']); + } + + /** + * Gets the contact id from it's username. + * @throws Exception + * @param string $username + * @return int + */ + protected function get_contact_id($username) { + global $DB; + + if (!$id = $DB->get_field('user', 'id', array('username' => $username))) { + throw new Exception('The specified user with username "' . $username . '" does not exist'); + } + return $id; + } } From 564ad754a8e458ccf59fc86fcb256db0662be6fa Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 13 Mar 2019 02:01:34 +0100 Subject: [PATCH 3/4] MDL-64664 core_message: Behat tests to manage contacts --- .../message_drawer_manage_contacts.feature | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 message/tests/behat/message_drawer_manage_contacts.feature diff --git a/message/tests/behat/message_drawer_manage_contacts.feature b/message/tests/behat/message_drawer_manage_contacts.feature new file mode 100644 index 00000000000..e1ec87f2638 --- /dev/null +++ b/message/tests/behat/message_drawer_manage_contacts.feature @@ -0,0 +1,77 @@ +@core @core_message @javascript +Feature: Manage contacts + In order to communicate with fellow users + As a user + I need to be able to add, decline and remove users + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | student3 | Student | 3 | student3@example.com | + | student4 | Student | 4 | student4@example.com | + And the following "message contacts" exist: + | user | contact | + | student1 | student2 | + And the following config values are set as admin: + | messaging | 1 | + | messagingallusers | 1 | + + Scenario: Send a 'contact request' to someone to add a contact + Given I log in as "student1" + Then I open messaging + And I select "Student 4" user in messaging + And I open contact menu + And I click on "Add to contacts" "link" + And I click on "Add" "button" + And I log out + And I log in as "student3" + And I select "Student 4" user in messaging + And I open contact menu + And I click on "Add to contacts" "link" + And I click on "Add" "button" + And I log out + And I log in as "student4" + Then I should see "2" in the "//*[@data-region='count-container']" "xpath_element" + And I open messaging + And I click on "Contacts" "link" + Then I should see "2" in the "//div[@data-region='view-contacts']//*[@data-region='contact-request-count']" "xpath_element" + And I click on "Requests" "link_or_button" + And I click on "Student 1 Would like to contact you" "link" + And I click on "Accept and add to contacts" "link_or_button" + And I log out + And I log in as "student1" + And I open messaging + And I click on "Contacts" "link" + And I should see "Student 4" in the "//*[@data-section='contacts']" "xpath_element" + + Scenario: Decline a 'contact request' from someone + Given I log in as "student1" + Then I open messaging + And I select "Student 3" user in messaging + And I open contact menu + And I click on "Add to contacts" "link" + And I click on "Add" "button" + And I log out + And I log in as "student3" + Then I should see "1" in the "//*[@data-region='count-container']" "xpath_element" + And I open messaging + And I click on "Contacts" "link" + Then I should see "1" in the "//div[@data-region='view-contacts']//*[@data-region='contact-request-count']" "xpath_element" + And I click on "Requests" "link_or_button" + And I click on "Student 1 Would like to contact you" "link" + And I click on "Decline" "link_or_button" + And I open contact menu + Then I should see "Add to contacts" in the "//div[@data-region='header-container']" "xpath_element" + + Scenario: Remove existing contact + Given I log in as "student1" + Then I open messaging + And I click on "Contacts" "link" + And I click on "Student 2" "link" in the "//*[@data-section='contacts']" "xpath_element" + And I open contact menu + And I click on "Remove from contacts" "link" + And I click on "Remove" "button" + And I go back in "view-conversation" message drawer + And I should see "No contacts" in the "//*[@data-region='empty-message-container']" "xpath_element" \ No newline at end of file From d0770f8154b795212ab785e2c338bf3a927ac2fc Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 27 Mar 2019 13:57:44 +0100 Subject: [PATCH 4/4] MDL-64664 core_message: Create more specific selector to contact menu --- message/tests/behat/behat_message.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/message/tests/behat/behat_message.php b/message/tests/behat/behat_message.php index f836def56f7..40c39f5f54d 100644 --- a/message/tests/behat/behat_message.php +++ b/message/tests/behat/behat_message.php @@ -194,11 +194,12 @@ class behat_message extends behat_base { * @Given /^I open contact menu$/ */ public function i_open_contact_menu() { - $this->execute('behat_general::i_click_on_in_the', + $this->execute('behat_general::wait_until_the_page_is_ready'); + $this->execute('behat_general::i_click_on_in_the', array( - '', 'button', - '[data-region="header-container"]', + 'css_element', + '[data-region="message-drawer"] [data-region="header-container"]', 'css_element', ) );