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

Data generator enrol_user should let you specify role shortname

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 2.9.4, 3.0.2
    • Component/s: Unit tests
    • Labels:

      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

            • Assignee:
              quen Sam Marshall
              Reporter:
              quen Sam Marshall
              Peer reviewer:
              Dan Poltawski
              Integrator:
              David Monllaó
              Tester:
              Andrew Nicols
              Participants:
              Component watchers:
              Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                11/Jan/16