MDL-64664 core_message: New data generator for contacts

This commit is contained in:
cescobedo
2019-03-18 09:50:00 +01:00
parent cbf62420e0
commit d940ccbe0b
+29
View File
@@ -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;
}
}