Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.1
-
MOODLE_31_STABLE
-
MOODLE_29_STABLE, MOODLE_30_STABLE
-
MDL-52558-master -
Description
In writing unit tests you often want to enrol users to a course, and sometimes with a role. In that case the following pattern is almost universal:
$studentroleid = $DB->get_field('role', 'id', array('shortname' => 'student'), MUST_EXIST); |
$generator->enrol_user($student1->id, $course->id, $studentroleid); |
This is a waste of time/space - the enrol_user function should accept a role shortname directly (nobody cares if new unit tests do a few extra get_field calls as a result). The above code will then become the much nicer:
$generator->enrol_user($student1->id, $course->id, 'student'); |