Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  namespace mod_assign;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  require_once($CFG->dirroot . '/lib/accesslib.php');
  23  require_once($CFG->dirroot . '/course/lib.php');
  24  
  25  /**
  26   * Unit tests for (some of) mod/assign/markerallocaion_test.php.
  27   *
  28   * @package    mod_assign
  29   * @category   test
  30   * @copyright  2017 Andrés Melo <andres.torres@blackboard.com>
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class markerallocation_test extends \advanced_testcase {
  34  
  35      /**
  36       * Create all the needed elements to test the difference between both functions.
  37       */
  38      public function test_markerusers() {
  39          $this->resetAfterTest();
  40          global $DB;
  41  
  42          // Create a course, by default it is created with 5 sections.
  43          $this->course = $this->getDataGenerator()->create_course();
  44  
  45          // Setting assing module, markingworkflow and markingallocation set to 1 to enable marker allocation.
  46          $record = new \stdClass();
  47          $record->course = $this->course;
  48  
  49          $modulesettings = array(
  50              'alwaysshowdescription'             => 1,
  51              'submissiondrafts'                  => 1,
  52              'requiresubmissionstatement'        => 0,
  53              'sendnotifications'                 => 0,
  54              'sendstudentnotifications'          => 1,
  55              'sendlatenotifications'             => 0,
  56              'duedate'                           => 0,
  57              'allowsubmissionsfromdate'          => 0,
  58              'grade'                             => 100,
  59              'cutoffdate'                        => 0,
  60              'teamsubmission'                    => 0,
  61              'requireallteammemberssubmit'       => 0,
  62              'teamsubmissiongroupingid'          => 0,
  63              'blindmarking'                      => 0,
  64              'attemptreopenmethod'               => 'none',
  65              'maxattempts'                       => -1,
  66              'markingworkflow'                   => 1,
  67              'markingallocation'                 => 1,
  68          );
  69  
  70          $assignelement = $this->getDataGenerator()->create_module('assign', $record, $modulesettings);
  71  
  72          $coursesectionid = course_add_cm_to_section($this->course->id, $assignelement->id, 1);
  73  
  74          // Adding users to the course.
  75          $userdata = array();
  76          $userdata['firstname'] = 'teacher1';
  77          $userdata['lasttname'] = 'lastname_teacher1';
  78  
  79          $user1 = $this->getDataGenerator()->create_user($userdata);
  80  
  81          $this->getDataGenerator()->enrol_user($user1->id, $this->course->id, 'teacher');
  82  
  83          $userdata = array();
  84          $userdata['firstname'] = 'teacher2';
  85          $userdata['lasttname'] = 'lastname_teacher2';
  86  
  87          $user2 = $this->getDataGenerator()->create_user($userdata);
  88  
  89          $this->getDataGenerator()->enrol_user($user2->id, $this->course->id, 'teacher');
  90  
  91          $userdata = array();
  92          $userdata['firstname'] = 'student';
  93          $userdata['lasttname'] = 'lastname_student';
  94  
  95          $user3 = $this->getDataGenerator()->create_user($userdata);
  96  
  97          $this->getDataGenerator()->enrol_user($user3->id, $this->course->id, 'student');
  98  
  99          // Adding manager to the system.
 100          $userdata = array();
 101          $userdata['firstname'] = 'Manager';
 102          $userdata['lasttname'] = 'lastname_Manager';
 103  
 104          $user4 = $this->getDataGenerator()->create_user($userdata);
 105  
 106          // Getting id of manager role.
 107          $managerrole = $DB->get_record('role', array('shortname' => 'manager'));
 108          if (!empty($managerrole)) {
 109              // By default the context of the system is assigned.
 110              $idassignment = $this->getDataGenerator()->role_assign($managerrole->id, $user4->id);
 111          }
 112  
 113          $oldusers = array($user1, $user2, $user4);
 114          $newusers = array($user1, $user2);
 115  
 116          list($sort, $params) = users_order_by_sql('u');
 117  
 118          // Old code, it must return 3 users: teacher1, teacher2 and Manger.
 119          $oldmarkers = get_users_by_capability(\context_course::instance($this->course->id), 'mod/assign:grade', '', $sort);
 120          // New code, it must return 2 users: teacher1 and teacher2.
 121          $newmarkers = get_enrolled_users(\context_course::instance($this->course->id), 'mod/assign:grade', 0, 'u.*', $sort);
 122  
 123          // Test result quantity.
 124          $this->assertEquals(count($oldusers), count($oldmarkers));
 125          $this->assertEquals(count($newusers), count($newmarkers));
 126          $this->assertEquals(count($oldmarkers) > count($newmarkers), true);
 127  
 128          // Elements expected with new code.
 129          foreach ($newmarkers as $key => $nm) {
 130              $this->assertEquals($nm, $newusers[array_search($nm, $newusers)]);
 131          }
 132  
 133          // Elements expected with old code.
 134          foreach ($oldusers as $key => $os) {
 135              $this->assertEquals($os->id, $oldmarkers[$os->id]->id);
 136              unset($oldmarkers[$os->id]);
 137          }
 138  
 139          $this->assertEquals(count($oldmarkers), 0);
 140  
 141      }
 142  }