From 7042ecf7edbff85e0179d3fd06d11ffe596e4215 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Wed, 3 Apr 2019 18:05:55 +0200 Subject: [PATCH] MDL-64666 core_message: Favourite private conversations data generator --- lib/tests/behat/behat_data_generators.php | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/tests/behat/behat_data_generators.php b/lib/tests/behat/behat_data_generators.php index 78c72e19b5b..8be665fa159 100644 --- a/lib/tests/behat/behat_data_generators.php +++ b/lib/tests/behat/behat_data_generators.php @@ -198,6 +198,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') + ), ); /** @@ -876,4 +886,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']); + } } -- 2.43.0