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_zoom\privacy;
|
|
|
18 |
|
|
|
19 |
use context_module;
|
|
|
20 |
use core_privacy\local\metadata\collection;
|
|
|
21 |
use core_privacy\local\request\approved_contextlist;
|
|
|
22 |
use core_privacy\local\request\approved_userlist;
|
|
|
23 |
use core_privacy\local\request\deletion_criteria;
|
|
|
24 |
use core_privacy\local\request\userlist;
|
|
|
25 |
use core_privacy\local\request\writer;
|
|
|
26 |
use core_privacy\tests\provider_testcase;
|
|
|
27 |
use mod_zoom\privacy\provider;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Privacy provider tests class.
|
|
|
31 |
*
|
|
|
32 |
* @package mod_zoom
|
|
|
33 |
* @copyright 2022 Catalyst IT Australia Pty Ltd
|
|
|
34 |
* @author 2022 Ghaly Marc-Alexandre <marc-alexandreghaly@catalyst-ca.net>
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
* @coversDefaultClass \mod_zoom\privacy\provider
|
|
|
37 |
*/
|
|
|
38 |
final class mod_zoom_provider_test extends provider_testcase {
|
|
|
39 |
/** @var object The zoom instance object. */
|
|
|
40 |
protected $zoominstance;
|
|
|
41 |
|
|
|
42 |
/** @var object The course object. */
|
|
|
43 |
protected $course;
|
|
|
44 |
|
|
|
45 |
/** @var object The student object. */
|
|
|
46 |
protected $student;
|
|
|
47 |
|
|
|
48 |
/** @var object The second student object. */
|
|
|
49 |
protected $student2;
|
|
|
50 |
|
|
|
51 |
/** @var object The course module object.*/
|
|
|
52 |
protected $cm;
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* {@inheritdoc}
|
|
|
56 |
*/
|
|
|
57 |
protected function setUp(): void {
|
|
|
58 |
$this->resetAfterTest();
|
|
|
59 |
$this->setAdminUser();
|
|
|
60 |
|
|
|
61 |
global $DB;
|
|
|
62 |
$generator = $this->getDataGenerator();
|
|
|
63 |
$course = $generator->create_course();
|
|
|
64 |
$params = [
|
|
|
65 |
'course' => $course->id,
|
|
|
66 |
'name' => 'First Zoom Activity',
|
|
|
67 |
'showpreview' => 0,
|
|
|
68 |
];
|
|
|
69 |
|
|
|
70 |
$plugingenerator = $generator->get_plugin_generator('mod_zoom');
|
|
|
71 |
// The zoom activity.
|
|
|
72 |
$zoom = $plugingenerator->create_instance($params);
|
|
|
73 |
// Create a student enrolled in zoom activity.
|
|
|
74 |
$student = $generator->create_user();
|
|
|
75 |
$student2 = $generator->create_user();
|
|
|
76 |
$studentrole = $DB->get_record('role', ['shortname' => 'student']);
|
|
|
77 |
$generator->enrol_user($student->id, $course->id, $studentrole->id);
|
|
|
78 |
$generator->enrol_user($student2->id, $course->id, $studentrole->id);
|
|
|
79 |
// Fill all related data tables.
|
|
|
80 |
$meeting = (object) [
|
|
|
81 |
'id' => 12345,
|
|
|
82 |
'meeting_id' => 12345,
|
|
|
83 |
'topic' => 'Some meeting',
|
|
|
84 |
'start_time' => 1646769060,
|
|
|
85 |
'end_time' => 1646715600,
|
|
|
86 |
'uuid' => 'someuuid',
|
|
|
87 |
'duration' => 60,
|
|
|
88 |
'participants' => 3,
|
|
|
89 |
'zoomid' => $zoom->id,
|
|
|
90 |
];
|
|
|
91 |
|
|
|
92 |
$zmid = $DB->insert_record('zoom_meeting_details', $meeting, true);
|
|
|
93 |
$participant = (object) [
|
|
|
94 |
'zoomuserid' => 9999,
|
|
|
95 |
'userid' => $student->id,
|
|
|
96 |
'join_time' => 1646769061,
|
|
|
97 |
'leave_time' => 1646769062,
|
|
|
98 |
'duration' => 60,
|
|
|
99 |
'name' => 'Michell',
|
|
|
100 |
'detailsid' => $zmid,
|
|
|
101 |
];
|
|
|
102 |
$participant2 = (object) [
|
|
|
103 |
'zoomuserid' => 9999,
|
|
|
104 |
'userid' => $student2->id,
|
|
|
105 |
'join_time' => 1646769061,
|
|
|
106 |
'leave_time' => 1646769062,
|
|
|
107 |
'duration' => 60,
|
|
|
108 |
'name' => 'John',
|
|
|
109 |
'detailsid' => $zmid,
|
|
|
110 |
];
|
|
|
111 |
$zmparticipantsid = $DB->insert_record('zoom_meeting_participants', $participant, true);
|
|
|
112 |
$zmparticipantsid2 = $DB->insert_record('zoom_meeting_participants', $participant2, true);
|
|
|
113 |
$meetingrecording = (object) [
|
|
|
114 |
'zoomid' => $zoom->id,
|
|
|
115 |
'meetinguuid' => 'meetinguuid',
|
|
|
116 |
'zoomrecordingid' => 'zoomrecordingid',
|
|
|
117 |
'name' => 'a zoom recording name',
|
|
|
118 |
'externalurl' => 'www.dummyurl.com',
|
|
|
119 |
'recordingtype' => 'recordingtype',
|
|
|
120 |
'recordingstart' => 1646769061,
|
|
|
121 |
'showrecording' => 1,
|
|
|
122 |
];
|
|
|
123 |
$meetingrecordingid = $DB->insert_record('zoom_meeting_recordings', $meetingrecording, true);
|
|
|
124 |
$meetingrecordingsview = (object) [
|
|
|
125 |
'recordingsid' => $meetingrecordingid,
|
|
|
126 |
'userid' => $student->id,
|
|
|
127 |
'viewed' => 1,
|
|
|
128 |
];
|
|
|
129 |
$meetingrecordingsview2 = (object) [
|
|
|
130 |
'recordingsid' => $meetingrecordingid,
|
|
|
131 |
'userid' => $student2->id,
|
|
|
132 |
'viewed' => 1,
|
|
|
133 |
];
|
|
|
134 |
$DB->insert_record('zoom_meeting_recordings_view', $meetingrecordingsview, true);
|
|
|
135 |
$DB->insert_record('zoom_meeting_recordings_view', $meetingrecordingsview2, true);
|
|
|
136 |
|
|
|
137 |
$cm = get_coursemodule_from_instance('zoom', $zoom->id);
|
|
|
138 |
|
|
|
139 |
$this->zoominstance = $zoom;
|
|
|
140 |
$this->course = $course;
|
|
|
141 |
$this->student = $student;
|
|
|
142 |
$this->student2 = $student2;
|
|
|
143 |
$this->cm = $cm;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Test for provider::get_metadata().
|
|
|
148 |
* @covers ::get_metadata
|
|
|
149 |
*/
|
|
|
150 |
public function test_get_metadata(): void {
|
|
|
151 |
$collection = new collection('mod_zoom');
|
|
|
152 |
$newcollection = provider::get_metadata($collection);
|
|
|
153 |
$itemcollection = $newcollection->get_collection();
|
|
|
154 |
|
|
|
155 |
$this->assertCount(4, $itemcollection);
|
|
|
156 |
$table = reset($itemcollection);
|
|
|
157 |
$table2 = $itemcollection[1];
|
|
|
158 |
$table3 = $itemcollection[2];
|
|
|
159 |
$table4 = $itemcollection[3];
|
|
|
160 |
$this->assertEquals('zoom_meeting_participants', $table->get_name());
|
|
|
161 |
$this->assertEquals('zoom_meeting_details', $table2->get_name());
|
|
|
162 |
$this->assertEquals('zoom_meeting_recordings_view', $table3->get_name());
|
|
|
163 |
$this->assertEquals('zoom_breakout_participants', $table4->get_name());
|
|
|
164 |
|
|
|
165 |
$privacyfields1 = $table->get_privacy_fields();
|
|
|
166 |
$this->assertArrayHasKey('name', $privacyfields1);
|
|
|
167 |
$this->assertArrayHasKey('user_email', $privacyfields1);
|
|
|
168 |
$this->assertArrayHasKey('join_time', $privacyfields1);
|
|
|
169 |
$this->assertArrayHasKey('leave_time', $privacyfields1);
|
|
|
170 |
$this->assertArrayHasKey('duration', $privacyfields1);
|
|
|
171 |
|
|
|
172 |
$this->assertEquals('privacy:metadata:zoom_meeting_participants', $table->get_summary());
|
|
|
173 |
|
|
|
174 |
$privacyfields2 = $table2->get_privacy_fields();
|
|
|
175 |
$this->assertArrayHasKey('topic', $privacyfields2);
|
|
|
176 |
|
|
|
177 |
$this->assertEquals('privacy:metadata:zoom_meeting_details', $table2->get_summary());
|
|
|
178 |
|
|
|
179 |
$privacyfields3 = $table3->get_privacy_fields();
|
|
|
180 |
$this->assertArrayHasKey('userid', $privacyfields3);
|
|
|
181 |
|
|
|
182 |
$this->assertEquals('privacy:metadata:zoom_meeting_view', $table3->get_summary());
|
|
|
183 |
|
|
|
184 |
$privacyfields4 = $table4->get_privacy_fields();
|
|
|
185 |
$this->assertArrayHasKey('userid', $privacyfields4);
|
|
|
186 |
|
|
|
187 |
$this->assertEquals('privacy:metadata:zoom_breakout_participants', $table4->get_summary());
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
/**
|
|
|
191 |
* Test for provider::get_contexts_for_userid().
|
|
|
192 |
* @covers ::get_contexts_for_userid
|
|
|
193 |
*/
|
|
|
194 |
public function test_get_contexts_for_userid(): void {
|
|
|
195 |
$contextlist = provider::get_contexts_for_userid($this->student->id);
|
|
|
196 |
$this->assertCount(1, $contextlist);
|
|
|
197 |
$contextforuser = $contextlist->current();
|
|
|
198 |
$cmcontext = context_module::instance($this->cm->id);
|
|
|
199 |
$this->assertEquals($cmcontext->id, $contextforuser->id);
|
|
|
200 |
|
|
|
201 |
$contextlist2 = provider::get_contexts_for_userid($this->student2->id);
|
|
|
202 |
$this->assertCount(1, $contextlist2);
|
|
|
203 |
$contextforuser2 = $contextlist2->current();
|
|
|
204 |
$cmcontext2 = context_module::instance($this->cm->id);
|
|
|
205 |
$this->assertEquals($cmcontext2->id, $contextforuser2->id);
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
/**
|
|
|
209 |
* Test for provider::get_users_in_context().
|
|
|
210 |
* @covers ::get_users_in_context
|
|
|
211 |
*/
|
|
|
212 |
public function test_get_users_in_context(): void {
|
|
|
213 |
$cmcontext = context_module::instance($this->cm->id);
|
|
|
214 |
|
|
|
215 |
$userlist = new userlist($cmcontext, 'mod_zoom');
|
|
|
216 |
provider::get_users_in_context($userlist);
|
|
|
217 |
|
|
|
218 |
$this->assertEquals([$this->student->id, $this->student2->id], $userlist->get_userids());
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
/**
|
|
|
222 |
* Test for provider::export_user_data().
|
|
|
223 |
* @covers ::export_user_data
|
|
|
224 |
*/
|
|
|
225 |
public function test_export_user_data(): void {
|
|
|
226 |
$cmcontext = context_module::instance($this->cm->id);
|
|
|
227 |
|
|
|
228 |
// Export all of the data for the context.
|
|
|
229 |
$this->export_context_data_for_user($this->student->id, $cmcontext, 'mod_zoom');
|
|
|
230 |
$writer = writer::with_context($cmcontext);
|
|
|
231 |
$this->assertTrue($writer->has_any_data());
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* Test for provider::delete_data_for_all_users_in_context().
|
|
|
236 |
* @covers ::delete_data_for_all_users_in_context
|
|
|
237 |
*/
|
|
|
238 |
public function test_delete_data_for_all_users_in_context(): void {
|
|
|
239 |
global $DB;
|
|
|
240 |
|
|
|
241 |
$zoommeetingcount = $DB->count_records('zoom_meeting_details');
|
|
|
242 |
$this->assertEquals(1, $zoommeetingcount);
|
|
|
243 |
|
|
|
244 |
$zmparticipants = $DB->count_records('zoom_meeting_participants');
|
|
|
245 |
$this->assertEquals(2, $zmparticipants);
|
|
|
246 |
|
|
|
247 |
$zmrecordingcount = $DB->count_records('zoom_meeting_recordings');
|
|
|
248 |
$this->assertEquals(1, $zmrecordingcount);
|
|
|
249 |
|
|
|
250 |
$zmrecordingviewcount = $DB->count_records('zoom_meeting_recordings_view');
|
|
|
251 |
$this->assertEquals(2, $zmrecordingviewcount);
|
|
|
252 |
|
|
|
253 |
// Delete data based on context.
|
|
|
254 |
$cmcontext = context_module::instance($this->cm->id);
|
|
|
255 |
provider::delete_data_for_all_users_in_context($cmcontext);
|
|
|
256 |
|
|
|
257 |
$newzoommeetingcount = $DB->count_records('zoom_meeting_details');
|
|
|
258 |
$this->assertEquals(0, $newzoommeetingcount);
|
|
|
259 |
|
|
|
260 |
$newzmparticipants = $DB->count_records('zoom_meeting_participants');
|
|
|
261 |
$this->assertEquals(0, $newzmparticipants);
|
|
|
262 |
|
|
|
263 |
$newzmrecordingcount = $DB->count_records('zoom_meeting_recordings');
|
|
|
264 |
$this->assertEquals(0, $newzmrecordingcount);
|
|
|
265 |
|
|
|
266 |
$newzmrecordingviewcount = $DB->count_records('zoom_meeting_recordings_view');
|
|
|
267 |
$this->assertEquals(0, $newzmrecordingviewcount);
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
/**
|
|
|
271 |
* Test for provider::delete_data_for_user().
|
|
|
272 |
* @covers ::delete_data_for_user
|
|
|
273 |
*/
|
|
|
274 |
public function test_delete_data_for_user(): void {
|
|
|
275 |
global $DB;
|
|
|
276 |
|
|
|
277 |
$zmparticipants = $DB->count_records('zoom_meeting_participants');
|
|
|
278 |
$this->assertEquals(2, $zmparticipants);
|
|
|
279 |
|
|
|
280 |
$zmrecordingviewcount = $DB->count_records('zoom_meeting_recordings_view');
|
|
|
281 |
$this->assertEquals(2, $zmrecordingviewcount);
|
|
|
282 |
// Delete data based on specific context.
|
|
|
283 |
$context = context_module::instance($this->cm->id);
|
|
|
284 |
$contextlist = new approved_contextlist($this->student, 'mod_zoom', [$context->id]);
|
|
|
285 |
|
|
|
286 |
provider::delete_data_for_user($contextlist);
|
|
|
287 |
|
|
|
288 |
$newzmparticipants = $DB->count_records('zoom_meeting_participants');
|
|
|
289 |
$this->assertEquals(1, $newzmparticipants);
|
|
|
290 |
|
|
|
291 |
$newzmrecordingviewcount = $DB->count_records('zoom_meeting_recordings_view');
|
|
|
292 |
$this->assertEquals(1, $newzmrecordingviewcount);
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
/**
|
|
|
296 |
* Test for provider::delete_data_for_users().
|
|
|
297 |
* @covers ::delete_data_for_users
|
|
|
298 |
*/
|
|
|
299 |
public function test_delete_data_for_users(): void {
|
|
|
300 |
global $DB;
|
|
|
301 |
|
|
|
302 |
$zmparticipants = $DB->count_records('zoom_meeting_participants');
|
|
|
303 |
$this->assertEquals(2, $zmparticipants);
|
|
|
304 |
|
|
|
305 |
$zmrecordingviewcount = $DB->count_records('zoom_meeting_recordings_view');
|
|
|
306 |
$this->assertEquals(2, $zmrecordingviewcount);
|
|
|
307 |
// Delete data based on specific context.
|
|
|
308 |
$context = context_module::instance($this->cm->id);
|
|
|
309 |
$approveduserlist = new approved_userlist(
|
|
|
310 |
$context,
|
|
|
311 |
'zoom',
|
|
|
312 |
[$this->student->id, $this->student2->id]
|
|
|
313 |
);
|
|
|
314 |
provider::delete_data_for_users($approveduserlist);
|
|
|
315 |
|
|
|
316 |
$newzmparticipants = $DB->count_records('zoom_meeting_participants');
|
|
|
317 |
$this->assertEquals(0, $newzmparticipants);
|
|
|
318 |
|
|
|
319 |
$newzmrecordingviewcount = $DB->count_records('zoom_meeting_recordings_view');
|
|
|
320 |
$this->assertEquals(0, $newzmrecordingviewcount);
|
|
|
321 |
}
|
|
|
322 |
}
|