MDL-64666 core_message: Favourite private conversations data generator

This commit is contained in:
Amaia Anabitarte 2019-04-03 18:05:55 +02:00
parent bc342f101a
commit a8915a3a7f

View File

@ -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($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($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']);
}
}