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_bigbluebuttonbn\external;
|
|
|
18 |
|
|
|
19 |
use core_external\external_api;
|
|
|
20 |
use mod_bigbluebuttonbn\instance;
|
|
|
21 |
use mod_bigbluebuttonbn\meeting;
|
|
|
22 |
use mod_bigbluebuttonbn\test\testcase_helper_trait;
|
|
|
23 |
use moodle_exception;
|
|
|
24 |
use require_login_exception;
|
|
|
25 |
use core_external\restricted_context_exception;
|
|
|
26 |
|
|
|
27 |
defined('MOODLE_INTERNAL') || die();
|
|
|
28 |
|
|
|
29 |
global $CFG;
|
|
|
30 |
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Tests for the update_course class.
|
|
|
34 |
*
|
|
|
35 |
* @package mod_bigbluebuttonbn
|
|
|
36 |
* @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
38 |
* @covers \mod_bigbluebuttonbn\external\end_meeting
|
|
|
39 |
*/
|
|
|
40 |
class end_meeting_test extends \externallib_advanced_testcase {
|
|
|
41 |
use testcase_helper_trait;
|
|
|
42 |
/**
|
|
|
43 |
* Setup for test
|
|
|
44 |
*/
|
|
|
45 |
public function setUp(): void {
|
|
|
46 |
parent::setUp();
|
|
|
47 |
$this->initialise_mock_server();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Helper
|
|
|
52 |
*
|
|
|
53 |
* @param mixed ...$params
|
|
|
54 |
* @return array|bool|mixed
|
|
|
55 |
*/
|
|
|
56 |
protected function end_meeting(...$params) {
|
|
|
57 |
$returnvalue = end_meeting::execute(...$params);
|
|
|
58 |
|
|
|
59 |
return external_api::clean_returnvalue(end_meeting::execute_returns(), $returnvalue);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Test execute API CALL with no instance
|
|
|
64 |
*/
|
|
|
65 |
public function test_execute_no_instance() {
|
|
|
66 |
$this->resetAfterTest();
|
|
|
67 |
$this->expectException(moodle_exception::class);
|
|
|
68 |
$endmeeting = $this->end_meeting(1234, 5678);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Test execute API CALL without login
|
|
|
73 |
*/
|
|
|
74 |
public function test_execute_without_login() {
|
|
|
75 |
$this->resetAfterTest();
|
|
|
76 |
|
|
|
77 |
$course = $this->getDataGenerator()->create_course();
|
|
|
78 |
$record = $this->getDataGenerator()->create_module('bigbluebuttonbn', ['course' => $course->id]);
|
|
|
79 |
$instance = instance::get_from_instanceid($record->id);
|
|
|
80 |
|
|
|
81 |
$this->expectException(require_login_exception::class);
|
|
|
82 |
$this->end_meeting($instance->get_instance_id(), 0);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Test execute API CALL with invalid login
|
|
|
87 |
*/
|
|
|
88 |
public function test_execute_with_invalid_login() {
|
|
|
89 |
$this->resetAfterTest();
|
|
|
90 |
|
|
|
91 |
$generator = $this->getDataGenerator();
|
|
|
92 |
$course = $generator->create_course();
|
|
|
93 |
$record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
|
|
|
94 |
$instance = instance::get_from_instanceid($record->id);
|
|
|
95 |
|
|
|
96 |
$user = $generator->create_user();
|
|
|
97 |
$this->setUser($user);
|
|
|
98 |
|
|
|
99 |
$this->expectException(require_login_exception::class);
|
|
|
100 |
$this->end_meeting($instance->get_instance_id(), 0);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* When login as a student
|
|
|
105 |
*/
|
|
|
106 |
public function test_execute_with_student_login() {
|
|
|
107 |
$this->resetAfterTest();
|
|
|
108 |
|
|
|
109 |
$generator = $this->getDataGenerator();
|
|
|
110 |
$course = $generator->create_course();
|
|
|
111 |
$record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
|
|
|
112 |
$instance = instance::get_from_instanceid($record->id);
|
|
|
113 |
|
|
|
114 |
$user = $generator->create_and_enrol($course, 'student');
|
|
|
115 |
$this->setUser($user);
|
|
|
116 |
|
|
|
117 |
$this->expectException(restricted_context_exception::class);
|
|
|
118 |
$this->end_meeting($instance->get_instance_id(), 0);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Test execute admin logic
|
|
|
123 |
*/
|
|
|
124 |
public function test_execute_with_admin_login() {
|
|
|
125 |
$this->resetAfterTest();
|
|
|
126 |
|
|
|
127 |
$generator = $this->getDataGenerator();
|
|
|
128 |
$course = $generator->create_course();
|
|
|
129 |
$record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
|
|
|
130 |
$instance = instance::get_from_instanceid($record->id);
|
|
|
131 |
|
|
|
132 |
$plugingenerator = $generator->get_plugin_generator('mod_bigbluebuttonbn');
|
|
|
133 |
$plugingenerator->create_meeting([
|
|
|
134 |
'instanceid' => $instance->get_instance_id(),
|
|
|
135 |
]);
|
|
|
136 |
|
|
|
137 |
$this->setAdminUser();
|
|
|
138 |
|
|
|
139 |
$result = $this->end_meeting($instance->get_instance_id(), 0);
|
|
|
140 |
$this->assertIsArray($result);
|
|
|
141 |
|
|
|
142 |
// TODO Check that the meeting was ended on the remote.
|
|
|
143 |
}
|
|
|
144 |
/**
|
|
|
145 |
* Test execute admin logic
|
|
|
146 |
*/
|
|
|
147 |
public function test_execute_end_meeting_already_ended() {
|
|
|
148 |
$this->resetAfterTest();
|
|
|
149 |
|
|
|
150 |
$generator = $this->getDataGenerator();
|
|
|
151 |
$course = $generator->create_course();
|
|
|
152 |
$record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
|
|
|
153 |
$instance = instance::get_from_instanceid($record->id);
|
|
|
154 |
|
|
|
155 |
$plugingenerator = $generator->get_plugin_generator('mod_bigbluebuttonbn');
|
|
|
156 |
$plugingenerator->create_meeting([
|
|
|
157 |
'instanceid' => $instance->get_instance_id(),
|
|
|
158 |
]);
|
|
|
159 |
|
|
|
160 |
// Then end the meeting.
|
|
|
161 |
// Execute the end command.
|
|
|
162 |
$meeting = new meeting($instance);
|
|
|
163 |
$meeting->end_meeting();
|
|
|
164 |
|
|
|
165 |
$this->setAdminUser();
|
|
|
166 |
|
|
|
167 |
$result = $this->end_meeting($instance->get_instance_id(), 0);
|
|
|
168 |
$this->assertIsArray($result);
|
|
|
169 |
|
|
|
170 |
// TODO Check that the meeting was ended on the remote.
|
|
|
171 |
}
|
|
|
172 |
}
|