MDL-38863 behat: Role assign generator

This commit is contained in:
David Monllao
2013-07-23 09:46:39 +02:00
parent ffc3f5308b
commit 72ddc05f67
3 changed files with 165 additions and 4 deletions
+28
View File
@@ -712,6 +712,34 @@ EOD;
$plugin->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status);
return true;
}
/**
* Assigns the specified role to a user in the context.
*
* @param int $roleid
* @param int $userid
* @param int $contextid Defaults to the system context
* @return int new/existing id of the assignment
*/
public function role_assign($roleid, $userid, $contextid = false) {
// Default to the system context.
if (!$contextid) {
$context = context_system::instance();
$contextid = $context->id;
}
if (empty($roleid)) {
throw new coding_exception('roleid must be present in testing_data_generator::role_assign() arguments');
}
if (empty($userid)) {
throw new coding_exception('userid must be present in testing_data_generator::role_assign() arguments');
}
return role_assign($roleid, $userid, $contextid);
}
}
/**