Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-52558

Data generator enrol_user should let you specify role shortname

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Minor
    • 2.9.4, 3.0.2
    • 3.1
    • Unit tests

    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');
      

      Attachments

        Activity

          People

            quen Sam Marshall
            quen Sam Marshall
            Dan Poltawski Dan Poltawski
            David Monllaó David Monllaó
            Andrew Lyons Andrew Lyons
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Clockify

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.