1 |
efrain |
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 |
/** @var \stdClass course record. */
|
|
|
36 |
private $course;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Create all the needed elements to test the difference between both functions.
|
|
|
40 |
*/
|
11 |
efrain |
41 |
public function test_markerusers(): void {
|
1 |
efrain |
42 |
$this->resetAfterTest();
|
|
|
43 |
global $DB;
|
|
|
44 |
|
|
|
45 |
// Create a course, by default it is created with 5 sections.
|
|
|
46 |
$this->course = $this->getDataGenerator()->create_course();
|
|
|
47 |
|
|
|
48 |
// Setting assing module, markingworkflow and markingallocation set to 1 to enable marker allocation.
|
|
|
49 |
$record = new \stdClass();
|
|
|
50 |
$record->course = $this->course;
|
|
|
51 |
|
|
|
52 |
$modulesettings = array(
|
|
|
53 |
'alwaysshowdescription' => 1,
|
|
|
54 |
'submissiondrafts' => 1,
|
|
|
55 |
'requiresubmissionstatement' => 0,
|
|
|
56 |
'sendnotifications' => 0,
|
|
|
57 |
'sendstudentnotifications' => 1,
|
|
|
58 |
'sendlatenotifications' => 0,
|
|
|
59 |
'duedate' => 0,
|
|
|
60 |
'allowsubmissionsfromdate' => 0,
|
|
|
61 |
'grade' => 100,
|
|
|
62 |
'cutoffdate' => 0,
|
|
|
63 |
'teamsubmission' => 0,
|
|
|
64 |
'requireallteammemberssubmit' => 0,
|
|
|
65 |
'teamsubmissiongroupingid' => 0,
|
|
|
66 |
'blindmarking' => 0,
|
|
|
67 |
'attemptreopenmethod' => 'none',
|
|
|
68 |
'maxattempts' => -1,
|
|
|
69 |
'markingworkflow' => 1,
|
|
|
70 |
'markingallocation' => 1,
|
|
|
71 |
);
|
|
|
72 |
|
|
|
73 |
$assignelement = $this->getDataGenerator()->create_module('assign', $record, $modulesettings);
|
|
|
74 |
|
|
|
75 |
$coursesectionid = course_add_cm_to_section($this->course->id, $assignelement->id, 1);
|
|
|
76 |
|
|
|
77 |
// Adding users to the course.
|
|
|
78 |
$userdata = array();
|
|
|
79 |
$userdata['firstname'] = 'teacher1';
|
|
|
80 |
$userdata['lasttname'] = 'lastname_teacher1';
|
|
|
81 |
|
|
|
82 |
$user1 = $this->getDataGenerator()->create_user($userdata);
|
|
|
83 |
|
|
|
84 |
$this->getDataGenerator()->enrol_user($user1->id, $this->course->id, 'teacher');
|
|
|
85 |
|
|
|
86 |
$userdata = array();
|
|
|
87 |
$userdata['firstname'] = 'teacher2';
|
|
|
88 |
$userdata['lasttname'] = 'lastname_teacher2';
|
|
|
89 |
|
|
|
90 |
$user2 = $this->getDataGenerator()->create_user($userdata);
|
|
|
91 |
|
|
|
92 |
$this->getDataGenerator()->enrol_user($user2->id, $this->course->id, 'teacher');
|
|
|
93 |
|
|
|
94 |
$userdata = array();
|
|
|
95 |
$userdata['firstname'] = 'student';
|
|
|
96 |
$userdata['lasttname'] = 'lastname_student';
|
|
|
97 |
|
|
|
98 |
$user3 = $this->getDataGenerator()->create_user($userdata);
|
|
|
99 |
|
|
|
100 |
$this->getDataGenerator()->enrol_user($user3->id, $this->course->id, 'student');
|
|
|
101 |
|
|
|
102 |
// Adding manager to the system.
|
|
|
103 |
$userdata = array();
|
|
|
104 |
$userdata['firstname'] = 'Manager';
|
|
|
105 |
$userdata['lasttname'] = 'lastname_Manager';
|
|
|
106 |
|
|
|
107 |
$user4 = $this->getDataGenerator()->create_user($userdata);
|
|
|
108 |
|
|
|
109 |
// Getting id of manager role.
|
|
|
110 |
$managerrole = $DB->get_record('role', array('shortname' => 'manager'));
|
|
|
111 |
if (!empty($managerrole)) {
|
|
|
112 |
// By default the context of the system is assigned.
|
|
|
113 |
$idassignment = $this->getDataGenerator()->role_assign($managerrole->id, $user4->id);
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
$oldusers = array($user1, $user2, $user4);
|
|
|
117 |
$newusers = array($user1, $user2);
|
|
|
118 |
|
|
|
119 |
list($sort, $params) = users_order_by_sql('u');
|
|
|
120 |
|
|
|
121 |
// Old code, it must return 3 users: teacher1, teacher2 and Manger.
|
|
|
122 |
$oldmarkers = get_users_by_capability(\context_course::instance($this->course->id), 'mod/assign:grade', '', $sort);
|
|
|
123 |
// New code, it must return 2 users: teacher1 and teacher2.
|
|
|
124 |
$newmarkers = get_enrolled_users(\context_course::instance($this->course->id), 'mod/assign:grade', 0, 'u.*', $sort);
|
|
|
125 |
|
|
|
126 |
// Test result quantity.
|
|
|
127 |
$this->assertEquals(count($oldusers), count($oldmarkers));
|
|
|
128 |
$this->assertEquals(count($newusers), count($newmarkers));
|
|
|
129 |
$this->assertEquals(count($oldmarkers) > count($newmarkers), true);
|
|
|
130 |
|
|
|
131 |
// Elements expected with new code.
|
|
|
132 |
foreach ($newmarkers as $key => $nm) {
|
|
|
133 |
$this->assertEquals($nm, $newusers[array_search($nm, $newusers)]);
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
// Elements expected with old code.
|
|
|
137 |
foreach ($oldusers as $key => $os) {
|
|
|
138 |
$this->assertEquals($os->id, $oldmarkers[$os->id]->id);
|
|
|
139 |
unset($oldmarkers[$os->id]);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
$this->assertEquals(count($oldmarkers), 0);
|
|
|
143 |
|
|
|
144 |
}
|
|
|
145 |
}
|