1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of the Zoom plugin for 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 supporting advanced password requirements in Zoom.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_zoom
|
|
|
21 |
* @copyright 2020 UC Regents
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
namespace mod_zoom;
|
|
|
26 |
|
|
|
27 |
use advanced_testcase;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* PHPunit testcase class.
|
|
|
31 |
*/
|
|
|
32 |
final class mod_zoom_grade_test extends advanced_testcase {
|
|
|
33 |
/**
|
|
|
34 |
* @var \stdClass Course record.
|
|
|
35 |
*/
|
|
|
36 |
private $course;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* @var \stdClass User record for teacher.
|
|
|
40 |
*/
|
|
|
41 |
private $teacher;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* @var \stdClass User record for student.
|
|
|
45 |
*/
|
|
|
46 |
private $student;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* @var \mod_zoom_generator Plugin generator for tests.
|
|
|
50 |
*/
|
|
|
51 |
private $generator;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Setup to ensure that fixtures are loaded.
|
|
|
55 |
*/
|
|
|
56 |
public static function setUpBeforeClass(): void {
|
|
|
57 |
global $CFG;
|
|
|
58 |
require_once($CFG->dirroot . '/mod/zoom/lib.php');
|
|
|
59 |
require_once($CFG->dirroot . '/mod/zoom/locallib.php');
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Setup before every test.
|
|
|
64 |
*/
|
|
|
65 |
public function setUp(): void {
|
|
|
66 |
$this->resetAfterTest();
|
|
|
67 |
$this->setAdminUser();
|
|
|
68 |
|
|
|
69 |
$this->course = $this->getDataGenerator()->create_course();
|
|
|
70 |
$this->teacher = $this->getDataGenerator()->create_and_enrol($this->course, 'teacher');
|
|
|
71 |
$this->student = $this->getDataGenerator()->create_and_enrol($this->course, 'student');
|
|
|
72 |
$this->generator = $this->getDataGenerator()->get_plugin_generator('mod_zoom');
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Tests that Zoom grades can be added and updated in the gradebook.
|
|
|
77 |
* @covers ::zoom_grade_item_update
|
|
|
78 |
*/
|
|
|
79 |
public function test_grade_added(): void {
|
|
|
80 |
$params['course'] = $this->course->id;
|
|
|
81 |
$params['grade'] = 100;
|
|
|
82 |
|
|
|
83 |
$instance = $this->generator->create_instance($params);
|
|
|
84 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
|
|
|
85 |
|
|
|
86 |
// Gradebook should be empty.
|
|
|
87 |
$this->assertEquals(0, count($gradebook->items[0]->grades));
|
|
|
88 |
|
|
|
89 |
// Insert grade for student.
|
|
|
90 |
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 50];
|
|
|
91 |
zoom_grade_item_update($instance, $studentgrade);
|
|
|
92 |
|
|
|
93 |
// Gradebook should contain a grade for student.
|
|
|
94 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
|
|
|
95 |
$this->assertEquals(1, count($gradebook->items[0]->grades));
|
|
|
96 |
$this->assertEquals(50, $gradebook->items[0]->grades[$this->student->id]->grade);
|
|
|
97 |
|
|
|
98 |
// Update grade for student.
|
|
|
99 |
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 75];
|
|
|
100 |
zoom_grade_item_update($instance, $studentgrade);
|
|
|
101 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
|
|
|
102 |
|
|
|
103 |
// Verify grade has been updated.
|
|
|
104 |
$this->assertEquals(1, count($gradebook->items[0]->grades));
|
|
|
105 |
$this->assertEquals(75, $gradebook->items[0]->grades[$this->student->id]->grade);
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
/**
|
|
|
109 |
* Tests that the Zoom grade type cannot be changed to NONE if grades are already inputted.
|
|
|
110 |
* @covers ::zoom_grade_item_update
|
|
|
111 |
*/
|
|
|
112 |
public function test_grade_type_not_none(): void {
|
|
|
113 |
$params['course'] = $this->course->id;
|
|
|
114 |
$params['grade'] = 100;
|
|
|
115 |
|
|
|
116 |
$instance = $this->generator->create_instance($params);
|
|
|
117 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
|
|
|
118 |
|
|
|
119 |
// Gradebook should be empty.
|
|
|
120 |
$this->assertEquals(0, count($gradebook->items[0]->grades));
|
|
|
121 |
|
|
|
122 |
// Insert grade for student.
|
|
|
123 |
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 100];
|
|
|
124 |
zoom_grade_item_update($instance, $studentgrade);
|
|
|
125 |
|
|
|
126 |
// Gradebook should contain a grade for student.
|
|
|
127 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
|
|
|
128 |
$this->assertEquals(1, count($gradebook->items[0]->grades));
|
|
|
129 |
|
|
|
130 |
// Try to change grade type to NONE.
|
|
|
131 |
$instance->grade = 0;
|
|
|
132 |
zoom_grade_item_update($instance);
|
|
|
133 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
|
|
|
134 |
|
|
|
135 |
// Verify grade type is not changed.
|
|
|
136 |
$this->assertEquals(100, $gradebook->items[0]->grademax);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* Tests that the Zoom grades can be deleted.
|
|
|
141 |
* @covers ::zoom_grade_item_delete
|
|
|
142 |
*/
|
|
|
143 |
public function test_grade_delete(): void {
|
|
|
144 |
$params['course'] = $this->course->id;
|
|
|
145 |
$params['grade'] = 100;
|
|
|
146 |
|
|
|
147 |
$instance = $this->generator->create_instance($params);
|
|
|
148 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
|
|
|
149 |
|
|
|
150 |
// Gradebook should be empty.
|
|
|
151 |
$this->assertEquals(0, count($gradebook->items[0]->grades));
|
|
|
152 |
|
|
|
153 |
// Insert grade for student.
|
|
|
154 |
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 100];
|
|
|
155 |
zoom_grade_item_update($instance, $studentgrade);
|
|
|
156 |
|
|
|
157 |
// Gradebook should contain a grade for student.
|
|
|
158 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
|
|
|
159 |
$this->assertEquals(1, count($gradebook->items[0]->grades));
|
|
|
160 |
|
|
|
161 |
// Delete the grade items.
|
|
|
162 |
zoom_grade_item_delete($instance);
|
|
|
163 |
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
|
|
|
164 |
|
|
|
165 |
// Verify gradebook is empty.
|
|
|
166 |
$this->assertEmpty($gradebook->items);
|
|
|
167 |
}
|
|
|
168 |
}
|