diff --git a/lib/tests/behat/behat_data_generators.php b/lib/tests/behat/behat_data_generators.php index 2577d462f4a..26ab9a68f97 100644 --- a/lib/tests/behat/behat_data_generators.php +++ b/lib/tests/behat/behat_data_generators.php @@ -188,6 +188,16 @@ class behat_data_generators extends behat_base { 'required' => array('user', 'contact'), 'switchids' => array('user' => 'userid', 'contact' => 'contactid') ), + 'private messages' => array( + 'datagenerator' => 'private_messages', + 'required' => array('user', 'contact', 'message'), + 'switchids' => array('user' => 'userid', 'contact' => 'contactid') + ), + 'favourite conversations' => array( + 'datagenerator' => 'favourite_conversations', + 'required' => array('user', 'contact'), + 'switchids' => array('user' => 'userid', 'contact' => 'contactid') + ), ); /** @@ -866,4 +876,38 @@ class behat_data_generators extends behat_base { } return $id; } + + /** + * Send a new message from user to contact in a private conversation + * + * @param array $data + * @return void + */ + protected function process_private_messages(array $data) { + if (!$conversationid = \core_message\api::get_conversation_between_users([$data['userid'], $data['contactid']])) { + $conversation = \core_message\api::create_conversation( + \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, + [$data['userid'], $data['contactid']] + ); + $conversationid = $conversation->id; + } + \core_message\api::send_message_to_conversation($data['userid'], $conversationid, $data['message'], FORMAT_PLAIN); + } + + /** + * Mark a private conversation as favourite for user + * + * @param array $data + * @return void + */ + protected function process_favourite_conversations(array $data) { + if (!$conversationid = \core_message\api::get_conversation_between_users([$data['userid'], $data['contactid']])) { + $conversation = \core_message\api::create_conversation( + \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, + [$data['userid'], $data['contactid']] + ); + $conversationid = $conversation->id; + } + \core_message\api::set_favourite_conversation($conversationid, $data['userid']); + } } diff --git a/message/tests/behat/message_delete_conversation.feature b/message/tests/behat/message_delete_conversation.feature new file mode 100644 index 00000000000..630a5dbc381 --- /dev/null +++ b/message/tests/behat/message_delete_conversation.feature @@ -0,0 +1,116 @@ +@core @core_message @javascript +Feature: Message delete conversations + In order to communicate with fellow users + As a user + I need to be able to delete conversations + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + And the following config values are set as admin: + | messaging | 1 | + | messagingallusers | 1 | + And the following "private messages" exist: + | user | contact | message | + | student1 | student2 | Hi! | + | student2 | student1 | What do you need? | + + Scenario: Delete a private conversation + And I log in as "student2" + And I open messaging + And I select "Student 1" conversation in the "messages" conversations list + And I open contact menu + And I click on "Delete conversation" "link" in the "//div[@data-region='header-container']" "xpath_element" +# Confirm deletion, so conversation should not be there + And I should see "Delete" + And I click on "//button[@data-action='confirm-delete-conversation']" "xpath_element" + And I should not see "Delete" + And I should not see "Hi!" in the "Student 1" "group_message_conversation" + And I should not see "What do you need?" in the "Student 1" "group_message_conversation" + And I should not see "##today##j F##" in the "Student 1" "group_message_conversation" +# Check user is deleting private conversation only for them + And I log out + And I log in as "student1" + And I open messaging + And I select "Student 2" conversation in the "messages" conversations list + And I should see "Hi!" in the "Student 2" "group_message_conversation" + And I should see "What do you need?" in the "Student 2" "group_message_conversation" + And I should see "##today##j F##" in the "Student 2" "group_message_conversation" + + Scenario: Cancel deleting a private conversation + Given I log in as "student1" + And I open messaging + And I select "Student 2" conversation in the "messages" conversations list + And I open contact menu + And I click on "Delete conversation" "link" in the "//div[@data-region='header-container']" "xpath_element" +# Cancel deletion, so conversation should be there + And I should see "Cancel" + And I click on "//button[@data-action='cancel-confirm']" "xpath_element" + And I should not see "Cancel" + And I should see "Hi!" in the "Student 2" "group_message_conversation" + And I should see "##today##j F##" in the "Student 2" "group_message_conversation" + + Scenario: Delete a stared conversation + Given the following "favourite conversations" exist: + | user | contact | + | student1 | student2 | + And I log in as "student1" + And I open messaging + And I select "Student 2" conversation in the "favourites" conversations list + And I open contact menu + And I click on "Delete conversation" "link" in the "//div[@data-region='header-container']" "xpath_element" +# Confirm deletion, so conversation should not be there + And I should see "Delete" + And I click on "//button[@data-action='confirm-delete-conversation']" "xpath_element" + And I should not see "Delete" + And I should not see "Hi!" in the "Student 2" "group_message_conversation" + And I should not see "What do you need?" in the "Student 2" "group_message_conversation" + And I should not see "##today##j F##" in the "Student 2" "group_message_conversation" +# Check user is deleting private conversation only for them + And I log out + And I log in as "student2" + And I open messaging + And I select "Student 1" conversation in the "messages" conversations list + And I should see "Hi!" in the "Student 1" "group_message_conversation" + And I should see "What do you need?" in the "Student 1" "group_message_conversation" + And I should see "##today##j F##" in the "Student 1" "group_message_conversation" + + Scenario: Cancel deleting a stared conversation + Given the following "favourite conversations" exist: + | user | contact | + | student1 | student2 | + When I log in as "student1" + And I open messaging + And I select "Student 2" conversation in the "favourites" conversations list + Then I should see "Hi!" in the "Student 2" "group_message_conversation" + And I should see "##today##j F##" in the "Student 2" "group_message_conversation" + And I open contact menu + And I click on "Delete conversation" "link" in the "//div[@data-region='header-container']" "xpath_element" +# Cancel deletion, so conversation should be there + And I should see "Cancel" + And I click on "//button[@data-action='cancel-confirm']" "xpath_element" + And I should not see "Cancel" + And I should see "Hi!" in the "Student 2" "group_message_conversation" + And I should see "##today##j F##" in the "Student 2" "group_message_conversation" + + Scenario: Check a deleted stared conversation is still stared + Given the following "favourite conversations" exist: + | user | contact | + | student1 | student2 | + When I log in as "student1" + And I open messaging + And I select "Student 2" conversation in the "favourites" conversations list + And I open contact menu + And I click on "Delete conversation" "link" in the "//div[@data-region='header-container']" "xpath_element" + Then I should see "Delete" + And I click on "//button[@data-action='confirm-delete-conversation']" "xpath_element" + And I should not see "Delete" + And I should not see "Hi!" in the "Student 2" "group_message_conversation" + And I go back in "view-conversation" message drawer + And I should not see "Student 2" in the "//*[@data-region='message-drawer']//div[@data-region='view-overview-favourites']" "xpath_element" + And I send "Hi!" message to "Student 2" user + And I go back in "view-conversation" message drawer + And I go back in "view-search" message drawer + And I should see "Student 2" in the "//*[@data-region='message-drawer']//div[@data-region='view-overview-favourites']" "xpath_element" \ No newline at end of file