Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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  /**
  18   * Unit tests for (some of) mod/assign/markerallocaion_test.php.
  19   *
  20   * @package    mod_assign
  21   * @category   test
  22   * @copyright  2017 Andrés Melo <andres.torres@blackboard.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  require_once($CFG->dirroot . '/lib/accesslib.php');
  30  require_once($CFG->dirroot . '/course/lib.php');
  31  
  32  /**
  33   * This class tests some of marker allocation functionality.
  34   *
  35   * @package    mod_assign
  36   * @copyright  2017 Andrés Melo <andres.torres@blackboard.com>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class mod_assign_markerallocation_testcase extends advanced_testcase {
  40  
  41      /**
  42       * Create all the needed elements to test the difference between both functions.
  43       */
  44      public function test_markerusers() {
  45          $this->resetAfterTest();
  46          global $DB;
  47  
  48          // Create a course, by default it is created with 5 sections.
  49          $this->course = $this->getDataGenerator()->create_course();
  50  
  51          // Setting assing module, markingworkflow and markingallocation set to 1 to enable marker allocation.
  52          $record = new stdClass();
  53          $record->course = $this->course;
  54  
  55          $modulesettings = array(
  56              'alwaysshowdescription'             => 1,
  57              'submissiondrafts'                  => 1,
  58              'requiresubmissionstatement'        => 0,
  59              'sendnotifications'                 => 0,
  60              'sendstudentnotifications'          => 1,
  61              'sendlatenotifications'             => 0,
  62              'duedate'                           => 0,
  63              'allowsubmissionsfromdate'          => 0,
  64              'grade'                             => 100,
  65              'cutoffdate'                        => 0,
  66              'teamsubmission'                    => 0,
  67              'requireallteammemberssubmit'       => 0,
  68              'teamsubmissiongroupingid'          => 0,
  69              'blindmarking'                      => 0,
  70              'attemptreopenmethod'               => 'none',
  71              'maxattempts'                       => -1,
  72              'markingworkflow'                   => 1,
  73              'markingallocation'                 => 1,
  74          );
  75  
  76          $assignelement = $this->getDataGenerator()->create_module('assign', $record, $modulesettings);
  77  
  78          $coursesectionid = course_add_cm_to_section($this->course->id, $assignelement->id, 1);
  79  
  80          // Adding users to the course.
  81          $userdata = array();
  82          $userdata['firstname'] = 'teacher1';
  83          $userdata['lasttname'] = 'lastname_teacher1';
  84  
  85          $user1 = $this->getDataGenerator()->create_user($userdata);
  86  
  87          $this->getDataGenerator()->enrol_user($user1->id, $this->course->id, 'teacher');
  88  
  89          $userdata = array();
  90          $userdata['firstname'] = 'teacher2';
  91          $userdata['lasttname'] = 'lastname_teacher2';
  92  
  93          $user2 = $this->getDataGenerator()->create_user($userdata);
  94  
  95          $this->getDataGenerator()->enrol_user($user2->id, $this->course->id, 'teacher');
  96  
  97          $userdata = array();
  98          $userdata['firstname'] = 'student';
  99          $userdata['lasttname'] = 'lastname_student';
 100  
 101          $user3 = $this->getDataGenerator()->create_user($userdata);
 102  
 103          $this->getDataGenerator()->enrol_user($user3->id, $this->course->id, 'student');
 104  
 105          // Adding manager to the system.
 106          $userdata = array();
 107          $userdata['firstname'] = 'Manager';
 108          $userdata['lasttname'] = 'lastname_Manager';
 109  
 110          $user4 = $this->getDataGenerator()->create_user($userdata);
 111  
 112          // Getting id of manager role.
 113          $managerrole = $DB->get_record('role', array('shortname' => 'manager'));
 114          if (!empty($managerrole)) {
 115              // By default the context of the system is assigned.
 116              $idassignment = $this->getDataGenerator()->role_assign($managerrole->id, $user4->id);
 117          }
 118  
 119          $oldusers = array($user1, $user2, $user4);
 120          $newusers = array($user1, $user2);
 121  
 122          list($sort, $params) = users_order_by_sql('u');
 123  
 124          // Old code, it must return 3 users: teacher1, teacher2 and Manger.
 125          $oldmarkers = get_users_by_capability(context_course::instance($this->course->id), 'mod/assign:grade', '', $sort);
 126          // New code, it must return 2 users: teacher1 and teacher2.
 127          $newmarkers = get_enrolled_users(context_course::instance($this->course->id), 'mod/assign:grade', 0, 'u.*', $sort);
 128  
 129          // Test result quantity.
 130          $this->assertEquals(count($oldusers), count($oldmarkers));
 131          $this->assertEquals(count($newusers), count($newmarkers));
 132          $this->assertEquals(count($oldmarkers) > count($newmarkers), true);
 133  
 134          // Elements expected with new code.
 135          foreach ($newmarkers as $key => $nm) {
 136              $this->assertEquals($nm, $newusers[array_search($nm, $newusers)]);
 137          }
 138  
 139          // Elements expected with old code.
 140          foreach ($oldusers as $key => $os) {
 141              $this->assertEquals($os->id, $oldmarkers[$os->id]->id);
 142              unset($oldmarkers[$os->id]);
 143          }
 144  
 145          $this->assertEquals(count($oldmarkers), 0);
 146  
 147      }
 148  }