forked from ncstate-delta/moodle-mod_zoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_zoom_grade_test.php
170 lines (139 loc) · 6.04 KB
/
mod_zoom_grade_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
// This file is part of the Zoom plugin for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for supporting advanced password requirements in Zoom.
*
* @package mod_zoom
* @copyright 2020 UC Regents
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_zoom;
use advanced_testcase;
/**
* PHPunit testcase class.
*/
final class mod_zoom_grade_test extends advanced_testcase {
/**
* @var \stdClass Course record.
*/
private $course;
/**
* @var \stdClass User record for teacher.
*/
private $teacher;
/**
* @var \stdClass User record for student.
*/
private $student;
/**
* @var \mod_zoom_generator Plugin generator for tests.
*/
private $generator;
/**
* Setup to ensure that fixtures are loaded.
*/
public static function setUpBeforeClass(): void {
global $CFG;
require_once($CFG->dirroot . '/mod/zoom/lib.php');
require_once($CFG->dirroot . '/mod/zoom/locallib.php');
parent::setUpBeforeClass();
}
/**
* Setup before every test.
*/
public function setUp(): void {
parent::setUp();
$this->resetAfterTest();
$this->setAdminUser();
$this->course = $this->getDataGenerator()->create_course();
$this->teacher = $this->getDataGenerator()->create_and_enrol($this->course, 'teacher');
$this->student = $this->getDataGenerator()->create_and_enrol($this->course, 'student');
$this->generator = $this->getDataGenerator()->get_plugin_generator('mod_zoom');
}
/**
* Tests that Zoom grades can be added and updated in the gradebook.
* @covers ::zoom_grade_item_update
*/
public function test_grade_added(): void {
$params['course'] = $this->course->id;
$params['grade'] = 100;
$instance = $this->generator->create_instance($params);
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
// Gradebook should be empty.
$this->assertEquals(0, count($gradebook->items[0]->grades));
// Insert grade for student.
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 50];
zoom_grade_item_update($instance, $studentgrade);
// Gradebook should contain a grade for student.
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
$this->assertEquals(1, count($gradebook->items[0]->grades));
$this->assertEquals(50, $gradebook->items[0]->grades[$this->student->id]->grade);
// Update grade for student.
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 75];
zoom_grade_item_update($instance, $studentgrade);
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
// Verify grade has been updated.
$this->assertEquals(1, count($gradebook->items[0]->grades));
$this->assertEquals(75, $gradebook->items[0]->grades[$this->student->id]->grade);
}
/**
* Tests that the Zoom grade type cannot be changed to NONE if grades are already inputted.
* @covers ::zoom_grade_item_update
*/
public function test_grade_type_not_none(): void {
$params['course'] = $this->course->id;
$params['grade'] = 100;
$instance = $this->generator->create_instance($params);
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
// Gradebook should be empty.
$this->assertEquals(0, count($gradebook->items[0]->grades));
// Insert grade for student.
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 100];
zoom_grade_item_update($instance, $studentgrade);
// Gradebook should contain a grade for student.
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
$this->assertEquals(1, count($gradebook->items[0]->grades));
// Try to change grade type to NONE.
$instance->grade = 0;
zoom_grade_item_update($instance);
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
// Verify grade type is not changed.
$this->assertEquals(100, $gradebook->items[0]->grademax);
}
/**
* Tests that the Zoom grades can be deleted.
* @covers ::zoom_grade_item_delete
*/
public function test_grade_delete(): void {
$params['course'] = $this->course->id;
$params['grade'] = 100;
$instance = $this->generator->create_instance($params);
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
// Gradebook should be empty.
$this->assertEquals(0, count($gradebook->items[0]->grades));
// Insert grade for student.
$studentgrade = ['userid' => $this->student->id, 'rawgrade' => 100];
zoom_grade_item_update($instance, $studentgrade);
// Gradebook should contain a grade for student.
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id, $this->student->id);
$this->assertEquals(1, count($gradebook->items[0]->grades));
// Delete the grade items.
zoom_grade_item_delete($instance);
$gradebook = grade_get_grades($this->course->id, 'mod', 'zoom', $instance->id);
// Verify gradebook is empty.
$this->assertEmpty($gradebook->items);
}
}