MDL-55609 testing: Add a create_and_enrol helper

This commit is contained in:
Andrew Nicols
2018-06-12 10:21:57 +02:00
committed by David Monllao
parent d2b6ce1555
commit 3714b3d104
+20
View File
@@ -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;
}
}