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 |
/**
|
|
|
18 |
* BBB Library tests class.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_bigbluebuttonbn
|
|
|
21 |
* @copyright 2018 - present, Blindside Networks Inc
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
* @author Laurent David (laurent@call-learning.fr)
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace mod_bigbluebuttonbn;
|
|
|
27 |
|
|
|
28 |
use calendar_event;
|
|
|
29 |
use context_module;
|
|
|
30 |
use mod_bigbluebuttonbn\test\testcase_helper_trait;
|
|
|
31 |
use mod_bigbluebuttonbn_mod_form;
|
|
|
32 |
use MoodleQuickForm;
|
|
|
33 |
use navigation_node;
|
|
|
34 |
use ReflectionClass;
|
|
|
35 |
use stdClass;
|
|
|
36 |
|
|
|
37 |
defined('MOODLE_INTERNAL') || die();
|
|
|
38 |
global $CFG;
|
|
|
39 |
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/lib.php');
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* BBB Library tests class.
|
|
|
43 |
*
|
|
|
44 |
* @package mod_bigbluebuttonbn
|
|
|
45 |
* @copyright 2018 - present, Blindside Networks Inc
|
|
|
46 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
47 |
* @author Laurent David (laurent@call-learning.fr)
|
|
|
48 |
*/
|
|
|
49 |
class lib_test extends \advanced_testcase {
|
|
|
50 |
use testcase_helper_trait;
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Check support
|
|
|
54 |
*
|
|
|
55 |
* @covers ::bigbluebuttonbn_supports
|
|
|
56 |
*/
|
11 |
efrain |
57 |
public function test_bigbluebuttonbn_supports(): void {
|
1 |
efrain |
58 |
$this->resetAfterTest();
|
|
|
59 |
$this->assertTrue(bigbluebuttonbn_supports(FEATURE_IDNUMBER));
|
|
|
60 |
$this->assertTrue(bigbluebuttonbn_supports(FEATURE_MOD_INTRO));
|
|
|
61 |
$this->assertFalse(bigbluebuttonbn_supports(FEATURE_GRADE_HAS_GRADE));
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Check add instance
|
|
|
66 |
*
|
|
|
67 |
* @covers ::bigbluebuttonbn_add_instance
|
|
|
68 |
*/
|
11 |
efrain |
69 |
public function test_bigbluebuttonbn_add_instance(): void {
|
1 |
efrain |
70 |
$this->resetAfterTest();
|
|
|
71 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
72 |
$bbformdata = $this->get_form_data_from_instance($bbactivity);
|
|
|
73 |
$id = bigbluebuttonbn_add_instance($bbformdata);
|
|
|
74 |
$this->assertNotNull($id);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Check update instance
|
|
|
79 |
*
|
|
|
80 |
* @covers ::bigbluebuttonbn_update_instance
|
|
|
81 |
*/
|
11 |
efrain |
82 |
public function test_bigbluebuttonbn_update_instance(): void {
|
1 |
efrain |
83 |
$this->resetAfterTest();
|
|
|
84 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
85 |
$bbformdata = $this->get_form_data_from_instance($bbactivity);
|
|
|
86 |
$result = bigbluebuttonbn_update_instance($bbformdata);
|
|
|
87 |
$this->assertTrue($result);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Check delete instance
|
|
|
92 |
*
|
|
|
93 |
* @covers ::bigbluebuttonbn_delete_instance
|
|
|
94 |
*/
|
11 |
efrain |
95 |
public function test_bigbluebuttonbn_delete_instance(): void {
|
1 |
efrain |
96 |
$this->resetAfterTest();
|
|
|
97 |
$this->initialise_mock_server();
|
|
|
98 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
99 |
$result = bigbluebuttonbn_delete_instance($bbactivity->id);
|
|
|
100 |
$this->assertTrue($result);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Check delete instance
|
|
|
105 |
*
|
|
|
106 |
* @covers ::bigbluebuttonbn_delete_instance
|
|
|
107 |
*/
|
11 |
efrain |
108 |
public function test_bigbluebuttonbn_delete_instance_with_running_meeting(): void {
|
1 |
efrain |
109 |
$this->resetAfterTest();
|
|
|
110 |
$this->initialise_mock_server();
|
|
|
111 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
112 |
$bbbgenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
|
|
|
113 |
$instance = instance::get_from_instanceid($bbactivity->id);
|
|
|
114 |
// Run the meeting.
|
|
|
115 |
$bbbgenerator->create_meeting([
|
|
|
116 |
'instanceid' => $instance->get_instance_id(),
|
|
|
117 |
'groupid' => $instance->get_group_id(),
|
|
|
118 |
]);
|
|
|
119 |
$meeting = new meeting($instance);
|
|
|
120 |
$meeting->update_cache();
|
|
|
121 |
$this->assertTrue($meeting->is_running());
|
|
|
122 |
$result = bigbluebuttonbn_delete_instance($bbactivity->id);
|
|
|
123 |
$this->assertTrue($result);
|
|
|
124 |
$meeting->update_cache();
|
|
|
125 |
$this->assertFalse($meeting->is_running());
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Check delete instance
|
|
|
130 |
*
|
|
|
131 |
* @covers ::bigbluebuttonbn_delete_instance
|
|
|
132 |
*/
|
11 |
efrain |
133 |
public function test_bigbluebuttonbn_delete_instance_with_running_group_meetings(): void {
|
1 |
efrain |
134 |
$this->resetAfterTest();
|
|
|
135 |
$this->initialise_mock_server();
|
|
|
136 |
$datagenerator = $this->getDataGenerator();
|
|
|
137 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
138 |
$course = $this->get_course();
|
|
|
139 |
set_coursemodule_groupmode($bbactivitycm->id, VISIBLEGROUPS);
|
|
|
140 |
|
|
|
141 |
$groups = [];
|
|
|
142 |
foreach (['G1', 'G2'] as $gname) {
|
|
|
143 |
$groups[] = $datagenerator->create_group(['courseid' => $course->id, 'name' => $gname]);
|
|
|
144 |
}
|
|
|
145 |
// Just create a user in one of the group so we check we don't just end meetings for this user...
|
|
|
146 |
$user = $datagenerator->create_and_enrol($this->get_course());
|
|
|
147 |
$groupids = array_map(function($g) {
|
|
|
148 |
return $g->id;
|
|
|
149 |
}, $groups);
|
|
|
150 |
$datagenerator->create_group_member(['userid' => $user->id, 'groupid' => $groupids[0]]);
|
|
|
151 |
$this->setUser($user);
|
|
|
152 |
|
|
|
153 |
$groupids[] = 0; // Add no group (id=0) - as an item so it is covered in the loop.
|
|
|
154 |
$bbbgenerator = $datagenerator->get_plugin_generator('mod_bigbluebuttonbn');
|
|
|
155 |
$globalinstance = instance::get_from_instanceid($bbactivity->id);
|
|
|
156 |
$meetings = [];
|
|
|
157 |
foreach ($groupids as $groupid) {
|
|
|
158 |
$instance = instance::get_group_instance_from_instance($globalinstance, $groupid);
|
|
|
159 |
// Run the meetings.
|
|
|
160 |
$bbbgenerator->create_meeting([
|
|
|
161 |
'instanceid' => $instance->get_instance_id(),
|
|
|
162 |
'groupid' => $instance->get_group_id(),
|
|
|
163 |
]);
|
|
|
164 |
$meeting = new meeting($instance);
|
|
|
165 |
$meeting->update_cache();
|
|
|
166 |
$this->assertTrue($meeting->is_running());
|
|
|
167 |
$meetings[] = $meeting;
|
|
|
168 |
}
|
|
|
169 |
$result = bigbluebuttonbn_delete_instance($bbactivity->id);
|
|
|
170 |
$this->assertTrue($result);
|
|
|
171 |
foreach ($meetings as $meeting) {
|
|
|
172 |
$meeting->update_cache();
|
|
|
173 |
$this->assertFalse($meeting->is_running());
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
/**
|
|
|
177 |
* Check user outline page
|
|
|
178 |
*
|
|
|
179 |
* @covers ::bigbluebuttonbn_user_outline
|
|
|
180 |
*/
|
11 |
efrain |
181 |
public function test_bigbluebuttonbn_user_outline(): void {
|
1 |
efrain |
182 |
$this->resetAfterTest();
|
|
|
183 |
|
|
|
184 |
$generator = $this->getDataGenerator();
|
|
|
185 |
$user = $generator->create_user();
|
|
|
186 |
$this->setUser($user);
|
|
|
187 |
|
|
|
188 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance($this->get_course(),
|
|
|
189 |
['completion' => 2, 'completionview' => 1]);
|
|
|
190 |
$result = bigbluebuttonbn_user_outline($this->get_course(), $user, $bbactivitycm, $bbactivity);
|
|
|
191 |
$this->assertEquals((object) ['info' => '', 'time' => 0], $result);
|
|
|
192 |
|
|
|
193 |
bigbluebuttonbn_view($bbactivity, $this->get_course(), $bbactivitycm, $bbactivitycontext);
|
|
|
194 |
$result = bigbluebuttonbn_user_outline($this->get_course(), $user, $bbactivitycm, $bbactivity);
|
|
|
195 |
$this->assertStringContainsString(get_string('report_room_view', 'mod_bigbluebuttonbn'), $result->info);
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
/**
|
|
|
199 |
* Check user completion
|
|
|
200 |
*
|
|
|
201 |
* @covers ::bigbluebuttonbn_user_complete
|
|
|
202 |
*/
|
11 |
efrain |
203 |
public function test_bigbluebuttonbn_user_complete(): void {
|
1 |
efrain |
204 |
$this->initialise_mock_server();
|
|
|
205 |
$this->resetAfterTest();
|
|
|
206 |
|
|
|
207 |
$generator = $this->getDataGenerator();
|
|
|
208 |
$user = $generator->create_and_enrol($this->get_course());
|
|
|
209 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance($this->get_course(),
|
|
|
210 |
['completion' => 2, 'completionview' => 1]);
|
|
|
211 |
$this->setUser($user);
|
|
|
212 |
|
|
|
213 |
// Now create a couple of logs.
|
|
|
214 |
bigbluebuttonbn_view($bbactivity, $this->get_course(), $bbactivitycm, $bbactivitycontext);
|
|
|
215 |
ob_start();
|
|
|
216 |
bigbluebuttonbn_user_complete($this->get_course(), $user, $bbactivitycm, $bbactivity);
|
|
|
217 |
$output = ob_get_contents();
|
|
|
218 |
ob_end_clean();
|
|
|
219 |
$this->assertStringContainsString(get_string('report_room_view', 'mod_bigbluebuttonbn'), $output);
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
/**
|
|
|
223 |
* Check get recent activity
|
|
|
224 |
*
|
|
|
225 |
* @covers ::bigbluebuttonbn_get_recent_mod_activity
|
|
|
226 |
*/
|
11 |
efrain |
227 |
public function test_bigbluebuttonbn_get_recent_mod_activity(): void {
|
1 |
efrain |
228 |
$this->initialise_mock_server();
|
|
|
229 |
$this->resetAfterTest();
|
|
|
230 |
|
|
|
231 |
$generator = $this->getDataGenerator();
|
|
|
232 |
$user = $generator->create_and_enrol($this->get_course());
|
|
|
233 |
$this->setUser($user);
|
|
|
234 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
235 |
// Now create a couple of logs.
|
|
|
236 |
$instance = instance::get_from_instanceid($bbactivity->id);
|
|
|
237 |
$recordings = $this->create_recordings_for_instance($instance, [['name' => "Pre-Recording 1"]]);
|
|
|
238 |
logger::log_meeting_joined_event($instance, 0);
|
|
|
239 |
logger::log_meeting_joined_event($instance, 0);
|
|
|
240 |
logger::log_recording_played_event($instance, $recordings[0]->id);
|
|
|
241 |
|
|
|
242 |
$activities = $this->prepare_for_recent_activity_array(0, $user->id, 0);
|
|
|
243 |
$this->assertCount(4, $activities);
|
|
|
244 |
$this->assertEquals(
|
|
|
245 |
["Meeting joined", "Meeting joined", "Recording viewed"],
|
|
|
246 |
array_values(
|
|
|
247 |
array_filter(
|
|
|
248 |
array_map(function($activity) {
|
|
|
249 |
return $activity->eventname ?? "";
|
|
|
250 |
}, $activities),
|
|
|
251 |
function($e) {
|
|
|
252 |
return !empty($e);
|
|
|
253 |
}
|
|
|
254 |
)
|
|
|
255 |
)
|
|
|
256 |
);
|
|
|
257 |
$this->assertEquals("Pre-Recording 1", $activities[3]->content); // The recording view event should contain the name
|
|
|
258 |
// of the activity.
|
|
|
259 |
}
|
|
|
260 |
|
|
|
261 |
/**
|
|
|
262 |
* Prepare the list of activities as is done in course recent activity
|
|
|
263 |
*
|
|
|
264 |
* @param int $date
|
|
|
265 |
* @param int $user
|
|
|
266 |
* @param int $group
|
|
|
267 |
* @return array|void
|
|
|
268 |
*/
|
|
|
269 |
protected function prepare_for_recent_activity_array($date, $user, $group) {
|
|
|
270 |
// Same algorithm as in cource/recent.php, but stops at the first bbb activity.
|
|
|
271 |
$course = $this->get_course();
|
|
|
272 |
$modinfo = get_fast_modinfo($course->id);
|
|
|
273 |
$sections = array();
|
|
|
274 |
$index = 0;
|
|
|
275 |
foreach ($modinfo->get_section_info_all() as $i => $section) {
|
|
|
276 |
if (!empty($section->uservisible)) {
|
|
|
277 |
$sections[$i] = $section;
|
|
|
278 |
}
|
|
|
279 |
}
|
|
|
280 |
foreach ($sections as $sectionnum => $section) {
|
|
|
281 |
|
|
|
282 |
$activity = new stdClass();
|
|
|
283 |
$activity->type = 'section';
|
|
|
284 |
if ($section->section > 0) {
|
|
|
285 |
$activity->name = get_section_name($this->get_course(), $section);
|
|
|
286 |
} else {
|
|
|
287 |
$activity->name = '';
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
$activity->visible = $section->visible;
|
|
|
291 |
$activities[$index++] = $activity;
|
|
|
292 |
|
|
|
293 |
if (empty($modinfo->sections[$sectionnum])) {
|
|
|
294 |
continue;
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
foreach ($modinfo->sections[$sectionnum] as $cmid) {
|
|
|
298 |
$cm = $modinfo->cms[$cmid];
|
|
|
299 |
|
|
|
300 |
if (!$cm->uservisible) {
|
|
|
301 |
continue;
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
if (!empty($filter) && $cm->modname != $filter) {
|
|
|
305 |
continue;
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
if (!empty($filtermodid) && $cmid != $filtermodid) {
|
|
|
309 |
continue;
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
if ($cm->modname == 'bigbluebuttonbn') {
|
|
|
313 |
return bigbluebuttonbn_get_recent_mod_activity($activities,
|
|
|
314 |
$index,
|
|
|
315 |
$date,
|
|
|
316 |
$course->id, $cmid,
|
|
|
317 |
$user,
|
|
|
318 |
$group);
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
/**
|
|
|
326 |
* Check user recent activity
|
|
|
327 |
*
|
|
|
328 |
* @covers ::bigbluebuttonbn_print_recent_mod_activity
|
|
|
329 |
*/
|
11 |
efrain |
330 |
public function test_bigbluebuttonbn_print_recent_mod_activity(): void {
|
1 |
efrain |
331 |
$this->initialise_mock_server();
|
|
|
332 |
$this->resetAfterTest();
|
|
|
333 |
|
|
|
334 |
$generator = $this->getDataGenerator();
|
|
|
335 |
$user = $generator->create_and_enrol($this->get_course());
|
|
|
336 |
$this->setUser($user);
|
|
|
337 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
338 |
// Now create a couple of logs.
|
|
|
339 |
$instance = instance::get_from_instanceid($bbactivity->id);
|
|
|
340 |
$recordings = $this->create_recordings_for_instance($instance, [['name' => "Pre-Recording 1"]]);
|
|
|
341 |
logger::log_meeting_joined_event($instance, 0);
|
|
|
342 |
logger::log_meeting_joined_event($instance, 0);
|
|
|
343 |
logger::log_recording_played_event($instance, $recordings[0]->id);
|
|
|
344 |
|
|
|
345 |
$activities = $this->prepare_for_recent_activity_array(0, $user->id, 0);
|
|
|
346 |
ob_start();
|
|
|
347 |
bigbluebuttonbn_print_recent_mod_activity($activities[1], $this->get_course()->id, false, [], false);
|
|
|
348 |
$output = ob_get_contents();
|
|
|
349 |
ob_end_clean();
|
|
|
350 |
$this->assertStringContainsString('Meeting joined', $output);
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
/**
|
|
|
355 |
* Check recent activity for the course
|
|
|
356 |
*
|
|
|
357 |
* @covers ::bigbluebuttonbn_print_recent_activity
|
|
|
358 |
*/
|
11 |
efrain |
359 |
public function test_bigbluebuttonbn_print_recent_activity(): void {
|
1 |
efrain |
360 |
global $CFG;
|
|
|
361 |
$this->initialise_mock_server();
|
|
|
362 |
$this->resetAfterTest();
|
|
|
363 |
|
|
|
364 |
$generator = $this->getDataGenerator();
|
|
|
365 |
$user = $generator->create_and_enrol($this->get_course());
|
|
|
366 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
367 |
// Now create a couple of logs.
|
|
|
368 |
$timestart = time() - HOURSECS;
|
|
|
369 |
$instance = instance::get_from_instanceid($bbactivity->id);
|
|
|
370 |
$recordings = $this->create_recordings_for_instance($instance, [['name' => "Pre-Recording 1"]]);
|
|
|
371 |
|
|
|
372 |
$this->setUser($user); // Important so the logs are set to this user.
|
|
|
373 |
logger::log_meeting_joined_event($instance, 0);
|
|
|
374 |
logger::log_meeting_joined_event($instance, 0);
|
|
|
375 |
logger::log_recording_played_event($instance, $recordings[0]->id);
|
|
|
376 |
|
|
|
377 |
$this->setAdminUser();
|
|
|
378 |
// Test that everything is displayed.
|
|
|
379 |
ob_start();
|
|
|
380 |
bigbluebuttonbn_print_recent_activity($this->get_course(), true, $timestart);
|
|
|
381 |
$output = ob_get_contents();
|
|
|
382 |
ob_end_clean();
|
|
|
383 |
$this->assertStringContainsString('Meeting joined', $output);
|
|
|
384 |
$this->assertStringContainsString(fullname($user), $output);
|
|
|
385 |
// Test that username are displayed in a different format.
|
|
|
386 |
$CFG->alternativefullnameformat = 'firstname lastname firstnamephonetic lastnamephonetic middlename alternatename';
|
|
|
387 |
$expectedname = "$user->firstname $user->lastname $user->firstnamephonetic "
|
|
|
388 |
. "$user->lastnamephonetic $user->middlename $user->alternatename";
|
|
|
389 |
ob_start();
|
|
|
390 |
bigbluebuttonbn_print_recent_activity($this->get_course(), false, $timestart);
|
|
|
391 |
$output = ob_get_contents();
|
|
|
392 |
ob_end_clean();
|
|
|
393 |
$this->assertStringContainsString('Meeting joined', $output);
|
|
|
394 |
$this->assertStringNotContainsString($expectedname, $output);
|
|
|
395 |
// Test that nothing is displayed as per timestart.
|
|
|
396 |
ob_start();
|
|
|
397 |
bigbluebuttonbn_print_recent_activity($this->get_course(), true, time());
|
|
|
398 |
$output = ob_get_contents();
|
|
|
399 |
ob_end_clean();
|
|
|
400 |
$this->assertEmpty($output);
|
|
|
401 |
}
|
|
|
402 |
|
|
|
403 |
/**
|
|
|
404 |
* Check extra capabilities return value
|
|
|
405 |
*
|
|
|
406 |
* @covers ::bigbluebuttonbn_get_extra_capabilities
|
|
|
407 |
*/
|
11 |
efrain |
408 |
public function test_bigbluebuttonbn_get_extra_capabilities(): void {
|
1 |
efrain |
409 |
$this->resetAfterTest();
|
|
|
410 |
$this->assertEquals(['moodle/site:accessallgroups'], bigbluebuttonbn_get_extra_capabilities());
|
|
|
411 |
}
|
|
|
412 |
|
|
|
413 |
/**
|
|
|
414 |
* Check form definition
|
|
|
415 |
*
|
|
|
416 |
* @covers ::bigbluebuttonbn_reset_course_form_definition
|
|
|
417 |
*/
|
11 |
efrain |
418 |
public function test_bigbluebuttonbn_reset_course_form_definition(): void {
|
1 |
efrain |
419 |
global $CFG, $PAGE;
|
|
|
420 |
$this->initialise_mock_server();
|
|
|
421 |
|
|
|
422 |
$PAGE->set_course($this->get_course());
|
|
|
423 |
$this->setAdminUser();
|
|
|
424 |
$this->resetAfterTest();
|
|
|
425 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
426 |
include_once($CFG->dirroot . '/mod/bigbluebuttonbn/mod_form.php');
|
|
|
427 |
$data = new stdClass();
|
|
|
428 |
$data->instance = $bbactivity;
|
|
|
429 |
$data->id = $bbactivity->id;
|
|
|
430 |
$data->course = $bbactivity->course;
|
|
|
431 |
|
|
|
432 |
$form = new mod_bigbluebuttonbn_mod_form($data, 1, $bbactivitycm, $this->get_course());
|
|
|
433 |
$refclass = new ReflectionClass("mod_bigbluebuttonbn_mod_form");
|
|
|
434 |
$formprop = $refclass->getProperty('_form');
|
|
|
435 |
|
|
|
436 |
/* @var $mform MoodleQuickForm quickform object definition */
|
|
|
437 |
$mform = $formprop->getValue($form);
|
|
|
438 |
bigbluebuttonbn_reset_course_form_definition($mform);
|
|
|
439 |
$this->assertNotNull($mform->getElement('bigbluebuttonbnheader'));
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
/**
|
|
|
443 |
* Check defaults for form
|
|
|
444 |
*
|
|
|
445 |
* @covers ::bigbluebuttonbn_reset_course_form_defaults
|
|
|
446 |
*/
|
11 |
efrain |
447 |
public function test_bigbluebuttonbn_reset_course_form_defaults(): void {
|
1 |
efrain |
448 |
global $CFG;
|
|
|
449 |
$this->resetAfterTest();
|
|
|
450 |
$results = bigbluebuttonbn_reset_course_form_defaults($this->get_course());
|
|
|
451 |
$this->assertEquals([
|
|
|
452 |
'reset_bigbluebuttonbn_events' => 0,
|
|
|
453 |
'reset_bigbluebuttonbn_tags' => 0,
|
|
|
454 |
'reset_bigbluebuttonbn_logs' => 0,
|
|
|
455 |
'reset_bigbluebuttonbn_recordings' => 0,
|
|
|
456 |
], $results);
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
/**
|
|
|
460 |
* Reset user data
|
|
|
461 |
*
|
|
|
462 |
* @covers ::bigbluebuttonbn_reset_userdata
|
|
|
463 |
*/
|
11 |
efrain |
464 |
public function test_bigbluebuttonbn_reset_userdata(): void {
|
1 |
efrain |
465 |
global $DB;
|
|
|
466 |
$this->resetAfterTest();
|
|
|
467 |
$data = new stdClass();
|
|
|
468 |
$user = $this->getDataGenerator()->create_user();
|
|
|
469 |
|
|
|
470 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
471 |
$this->getDataGenerator()->enrol_user($user->id, $this->course->id);
|
|
|
472 |
$this->setUser($user);
|
|
|
473 |
|
|
|
474 |
logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity->id), 0);
|
|
|
475 |
$data->courseid = $this->get_course()->id;
|
|
|
476 |
$data->reset_bigbluebuttonbn_tags = true;
|
|
|
477 |
$data->reset_bigbluebuttonbn_logs = true;
|
|
|
478 |
$data->course = $bbactivity->course;
|
|
|
479 |
// Add and Join.
|
|
|
480 |
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
|
|
|
481 |
$results = bigbluebuttonbn_reset_userdata($data);
|
|
|
482 |
$this->assertCount(0, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
|
|
|
483 |
$this->assertEquals([
|
|
|
484 |
'component' => 'BigBlueButton',
|
|
|
485 |
'item' => 'Deleted tags',
|
|
|
486 |
'error' => false
|
|
|
487 |
],
|
|
|
488 |
$results[0]
|
|
|
489 |
);
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
/**
|
|
|
493 |
* Reset user data in a course and checks it does not delete logs elsewhere
|
|
|
494 |
*
|
|
|
495 |
* @covers ::bigbluebuttonbn_reset_userdata
|
|
|
496 |
*/
|
11 |
efrain |
497 |
public function test_bigbluebuttonbn_reset_userdata_in_a_course(): void {
|
1 |
efrain |
498 |
global $DB;
|
|
|
499 |
$this->resetAfterTest();
|
|
|
500 |
$data = new stdClass();
|
|
|
501 |
$user = $this->getDataGenerator()->create_user();
|
|
|
502 |
|
|
|
503 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
504 |
$this->getDataGenerator()->enrol_user($user->id, $this->course->id);
|
|
|
505 |
logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity->id), 0);
|
|
|
506 |
|
|
|
507 |
// Now create another activity in a course and add a couple of logs.
|
|
|
508 |
// Aim is to make sure that only logs from one course are deleted.
|
|
|
509 |
$course1 = $this->getDataGenerator()->create_course();
|
|
|
510 |
list($bbactivitycontext1, $bbactivitycm1, $bbactivity1) = $this->create_instance($course1);
|
|
|
511 |
logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity1->id), 0);
|
|
|
512 |
|
|
|
513 |
$data->courseid = $this->get_course()->id;
|
|
|
514 |
$data->reset_bigbluebuttonbn_tags = true;
|
|
|
515 |
$data->reset_bigbluebuttonbn_logs = true;
|
|
|
516 |
$data->course = $bbactivity->course;
|
|
|
517 |
// Add and Join.
|
|
|
518 |
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
|
|
|
519 |
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity1->id]));
|
|
|
520 |
bigbluebuttonbn_reset_userdata($data);
|
|
|
521 |
$this->assertCount(0, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
|
|
|
522 |
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity1->id]));
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
/**
|
|
|
526 |
* Reset user data in a course but do not delete logs
|
|
|
527 |
*
|
|
|
528 |
* @covers ::bigbluebuttonbn_reset_userdata
|
|
|
529 |
*/
|
11 |
efrain |
530 |
public function test_bigbluebuttonbn_reset_userdata_logs_not_deleted(): void {
|
1 |
efrain |
531 |
global $DB;
|
|
|
532 |
$this->resetAfterTest();
|
|
|
533 |
$data = new stdClass();
|
|
|
534 |
$user = $this->getDataGenerator()->create_user();
|
|
|
535 |
|
|
|
536 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
537 |
$this->getDataGenerator()->enrol_user($user->id, $this->course->id);
|
|
|
538 |
$this->setUser($user);
|
|
|
539 |
logger::log_meeting_joined_event(instance::get_from_instanceid($bbactivity->id), 0);
|
|
|
540 |
|
|
|
541 |
$data->courseid = $this->get_course()->id;
|
|
|
542 |
$data->reset_bigbluebuttonbn_logs = false;
|
|
|
543 |
$data->course = $bbactivity->course;
|
|
|
544 |
// Add and Join.
|
|
|
545 |
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
|
|
|
546 |
bigbluebuttonbn_reset_userdata($data);
|
|
|
547 |
$this->assertCount(2, $DB->get_records('bigbluebuttonbn_logs', ['bigbluebuttonbnid' => $bbactivity->id]));
|
|
|
548 |
}
|
|
|
549 |
|
|
|
550 |
/**
|
|
|
551 |
* Check course module
|
|
|
552 |
*
|
|
|
553 |
* @covers ::bigbluebuttonbn_get_coursemodule_info
|
|
|
554 |
*/
|
11 |
efrain |
555 |
public function test_bigbluebuttonbn_get_coursemodule_info(): void {
|
1 |
efrain |
556 |
$this->resetAfterTest();
|
|
|
557 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
558 |
$info = bigbluebuttonbn_get_coursemodule_info($bbactivitycm);
|
|
|
559 |
$this->assertEquals($info->name, $bbactivity->name);
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
/**
|
|
|
563 |
* Check update since
|
|
|
564 |
*
|
|
|
565 |
* @covers ::bigbluebuttonbn_check_updates_since
|
|
|
566 |
*/
|
11 |
efrain |
567 |
public function test_bigbluebuttonbn_check_updates_since(): void {
|
1 |
efrain |
568 |
$this->resetAfterTest();
|
|
|
569 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
570 |
$result = bigbluebuttonbn_check_updates_since($bbactivitycm, 0);
|
|
|
571 |
$this->assertEquals(
|
|
|
572 |
'{"configuration":{"updated":false},"contentfiles":{"updated":false},"introfiles":' .
|
|
|
573 |
'{"updated":false},"completion":{"updated":false}}',
|
|
|
574 |
json_encode($result)
|
|
|
575 |
);
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
/**
|
|
|
579 |
* Check event action (calendar)
|
|
|
580 |
*
|
|
|
581 |
* @covers ::mod_bigbluebuttonbn_core_calendar_provide_event_action
|
|
|
582 |
*/
|
11 |
efrain |
583 |
public function test_mod_bigbluebuttonbn_core_calendar_provide_event_action(): void {
|
1 |
efrain |
584 |
global $DB;
|
|
|
585 |
$this->initialise_mock_server();
|
|
|
586 |
$this->resetAfterTest();
|
|
|
587 |
$this->setAdminUser();
|
|
|
588 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
589 |
|
|
|
590 |
// Standard use case, the meeting start and we want add an action event to join the meeting.
|
|
|
591 |
$event = $this->create_action_event($this->get_course(), $bbactivity, logger::EVENT_MEETING_START);
|
|
|
592 |
$factory = new \core_calendar\action_factory();
|
|
|
593 |
$actionevent = mod_bigbluebuttonbn_core_calendar_provide_event_action($event, $factory);
|
|
|
594 |
$this->assertEquals("Join session", $actionevent->get_name());
|
|
|
595 |
|
|
|
596 |
// User has already joined the meeting (there is log event EVENT_JOIN already for this user).
|
|
|
597 |
$instance = instance::get_from_instanceid($bbactivity->id);
|
|
|
598 |
logger::log_meeting_joined_event($instance, 0);
|
|
|
599 |
|
|
|
600 |
$bbactivity->closingtime = time() - 1000;
|
|
|
601 |
$bbactivity->openingtime = time() - 2000;
|
|
|
602 |
$DB->update_record('bigbluebuttonbn', $bbactivity);
|
|
|
603 |
$event = $this->create_action_event($this->get_course(), $bbactivity, logger::EVENT_MEETING_START);
|
|
|
604 |
$actionevent = mod_bigbluebuttonbn_core_calendar_provide_event_action($event, $factory);
|
|
|
605 |
$this->assertNull($actionevent);
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
/**
|
|
|
609 |
* Creates an action event.
|
|
|
610 |
*
|
|
|
611 |
* @param stdClass $course The course the bigbluebutton activity is in
|
|
|
612 |
* @param stdClass $bbbactivity The bigbluebutton activity to create an event for
|
|
|
613 |
* @param string $eventtype The event type. eg. ASSIGN_EVENT_TYPE_DUE.
|
|
|
614 |
* @return bool|calendar_event
|
|
|
615 |
*/
|
|
|
616 |
private function create_action_event(stdClass $course, stdClass $bbbactivity, string $eventtype) {
|
|
|
617 |
$event = new stdClass();
|
|
|
618 |
$event->name = 'Calendar event';
|
|
|
619 |
$event->modulename = 'bigbluebuttonbn';
|
|
|
620 |
$event->courseid = $course->id;
|
|
|
621 |
$event->instance = $bbbactivity->id;
|
|
|
622 |
$event->type = CALENDAR_EVENT_TYPE_ACTION;
|
|
|
623 |
$event->priority = CALENDAR_EVENT_USER_OVERRIDE_PRIORITY;
|
|
|
624 |
$event->eventtype = $eventtype;
|
|
|
625 |
$event->timestart = time();
|
|
|
626 |
|
|
|
627 |
return calendar_event::create($event);
|
|
|
628 |
}
|
|
|
629 |
|
|
|
630 |
/**
|
|
|
631 |
* Test setting navigation admin menu
|
|
|
632 |
*
|
|
|
633 |
* @covers ::bigbluebuttonbn_extend_settings_navigation
|
|
|
634 |
*/
|
11 |
efrain |
635 |
public function test_bigbluebuttonbn_extend_settings_navigation_admin(): void {
|
1 |
efrain |
636 |
global $PAGE, $CFG;
|
|
|
637 |
$this->resetAfterTest();
|
|
|
638 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
639 |
$CFG->bigbluebuttonbn_meetingevents_enabled = true;
|
|
|
640 |
|
|
|
641 |
$PAGE->set_cm($bbactivitycm);
|
|
|
642 |
$PAGE->set_context(context_module::instance($bbactivitycm->id));
|
|
|
643 |
$PAGE->set_url('/mod/bigbluebuttonbn/view.php', ['id' => $bbactivitycm->id]);
|
|
|
644 |
$settingnav = $PAGE->settingsnav;
|
|
|
645 |
|
|
|
646 |
$this->setAdminUser();
|
|
|
647 |
$node = navigation_node::create('testnavigationnode');
|
|
|
648 |
bigbluebuttonbn_extend_settings_navigation($settingnav, $node);
|
|
|
649 |
$this->assertCount(1, $node->get_children_key_list());
|
|
|
650 |
}
|
|
|
651 |
|
|
|
652 |
/**
|
|
|
653 |
* Check additional setting menu
|
|
|
654 |
*
|
|
|
655 |
* @covers ::bigbluebuttonbn_extend_settings_navigation
|
|
|
656 |
*/
|
11 |
efrain |
657 |
public function test_bigbluebuttonbn_extend_settings_navigation_user(): void {
|
1 |
efrain |
658 |
global $PAGE, $CFG;
|
|
|
659 |
$this->resetAfterTest();
|
|
|
660 |
|
|
|
661 |
$generator = $this->getDataGenerator();
|
|
|
662 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
663 |
$user = $generator->create_user();
|
|
|
664 |
$this->setUser($user);
|
|
|
665 |
list($course, $bbactivitycmuser) = get_course_and_cm_from_instance($bbactivity->id, 'bigbluebuttonbn');
|
|
|
666 |
|
|
|
667 |
$CFG->bigbluebuttonbn_meetingevents_enabled = true;
|
|
|
668 |
|
|
|
669 |
$PAGE->set_cm($bbactivitycmuser);
|
|
|
670 |
$PAGE->set_context(context_module::instance($bbactivitycm->id));
|
|
|
671 |
$PAGE->set_url('/mod/bigbluebuttonbn/view.php', ['id' => $bbactivitycm->id]);
|
|
|
672 |
|
|
|
673 |
$settingnav = $PAGE->settingsnav;
|
|
|
674 |
$node = navigation_node::create('testnavigationnode');
|
|
|
675 |
bigbluebuttonbn_extend_settings_navigation($settingnav, $node);
|
|
|
676 |
$this->assertCount(0, $node->get_children_key_list());
|
|
|
677 |
}
|
|
|
678 |
|
|
|
679 |
/**
|
|
|
680 |
* Check the visibility on calendar
|
|
|
681 |
* @covers ::mod_bigbluebuttonbn_core_calendar_is_event_visible
|
|
|
682 |
*/
|
11 |
efrain |
683 |
public function test_mod_bigbluebuttonbn_core_calendar_is_event_visible(): void {
|
1 |
efrain |
684 |
global $DB;
|
|
|
685 |
$this->resetAfterTest();
|
|
|
686 |
$this->setAdminUser();
|
|
|
687 |
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
|
|
|
688 |
$bbactivity->closingtime = time() - 1000;
|
|
|
689 |
$bbactivity->openingtime = time() - 2000;
|
|
|
690 |
$DB->update_record('bigbluebuttonbn', $bbactivity);
|
|
|
691 |
$event = $this->create_action_event($this->get_course(), $bbactivity, logger::EVENT_MEETING_START);
|
|
|
692 |
$this->assertFalse(mod_bigbluebuttonbn_core_calendar_is_event_visible($event));
|
|
|
693 |
$bbactivity->closingtime = time() + 1000;
|
|
|
694 |
$DB->update_record('bigbluebuttonbn', $bbactivity);
|
|
|
695 |
$event = $this->create_action_event($this->get_course(), $bbactivity, logger::EVENT_MEETING_START);
|
|
|
696 |
$this->assertTrue(mod_bigbluebuttonbn_core_calendar_is_event_visible($event));
|
|
|
697 |
$event->instance = 0;
|
|
|
698 |
$this->assertFalse(mod_bigbluebuttonbn_core_calendar_is_event_visible($event));
|
|
|
699 |
}
|
|
|
700 |
|
|
|
701 |
}
|