mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-55609 testing: Add a create_and_enrol helper
This commit is contained in:
parent
5b4ca9eb5b
commit
e984917db8
@ -1163,4 +1163,24 @@ EOD;
|
||||
|
||||
return $event->properties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user, and enrol them in the specified course as the supplied role.
|
||||
*
|
||||
* @param \stdClass $course The course to enrol in
|
||||
* @param string $role The role to give within the course
|
||||
* @param \stdClass $userparams User parameters
|
||||
* @return \stdClass The created user
|
||||
*/
|
||||
public function create_and_enrol($course, $role = 'student', $userparams = null, $enrol = 'manual',
|
||||
$timestart = 0, $timeend = 0, $status = null) {
|
||||
global $DB;
|
||||
|
||||
$user = $this->create_user($userparams);
|
||||
$roleid = $DB->get_field('role', 'id', ['shortname' => $role ]);
|
||||
|
||||
$this->enrol_user($user->id, $course->id, $roleid, $enrol, $timestart, $timeend, $status);
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user