Differences Between: [Versions 400 and 402] [Versions 401 and 402]
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\test\testcase_helper_trait; 22 use moodle_exception; 23 24 defined('MOODLE_INTERNAL') || die(); 25 26 global $CFG; 27 require_once($CFG->dirroot . '/webservice/tests/helpers.php'); 28 29 /** 30 * Tests for the get_join_url class. 31 * 32 * @package mod_bigbluebuttonbn 33 * @category test 34 * @copyright 2021 - present, Blindside Networks Inc 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 * @author Laurent David (laurent@call-learning.fr) 37 * @covers \mod_bigbluebuttonbn\external\get_join_url 38 */ 39 class get_join_url_test extends \externallib_advanced_testcase { 40 use testcase_helper_trait; 41 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 mixed 55 */ 56 protected function get_join_url(...$params) { 57 $getjoinurl = get_join_url::execute(...$params); 58 59 return external_api::clean_returnvalue(get_join_url::execute_returns(), $getjoinurl); 60 } 61 62 /** 63 * Test execute API CALL with no instance 64 */ 65 public function test_execute_no_instance() { 66 $this->expectExceptionMessageMatches('/No such instance.*/'); 67 $joinurl = $this->get_join_url(1234, 5678); 68 69 $this->assertIsArray($joinurl); 70 $this->assertArrayNotHasKey('join_url', $joinurl); 71 $this->assertEquals(false, $joinurl['join_url']); 72 } 73 74 /** 75 * Test execute API CALL without login 76 */ 77 public function test_execute_without_login() { 78 $this->resetAfterTest(); 79 80 $course = $this->getDataGenerator()->create_course(); 81 $record = $this->getDataGenerator()->create_module('bigbluebuttonbn', ['course' => $course->id]); 82 $instance = instance::get_from_instanceid($record->id); 83 84 $this->expectException(moodle_exception::class); 85 $this->get_join_url($instance->get_cm_id()); 86 } 87 88 /** 89 * Test execute API CALL with invalid login 90 */ 91 public function test_execute_with_invalid_login() { 92 $this->resetAfterTest(); 93 94 $generator = $this->getDataGenerator(); 95 $course = $generator->create_course(); 96 $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]); 97 $instance = instance::get_from_instanceid($record->id); 98 99 $user = $generator->create_user(); 100 $this->setUser($user); 101 102 $this->expectException(moodle_exception::class); 103 $this->get_join_url($instance->get_cm_id()); 104 } 105 106 /** 107 * When login as a student 108 */ 109 public function test_execute_with_valid_login() { 110 $this->resetAfterTest(); 111 112 $generator = $this->getDataGenerator(); 113 $course = $generator->create_course(); 114 $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]); 115 $instance = instance::get_from_instanceid($record->id); 116 117 $user = $generator->create_and_enrol($course, 'student'); 118 $bbbgenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn'); 119 // Make sure the meeting is running (this is not the default with the mock server). 120 $bbbgenerator->create_meeting([ 121 'instanceid' => $instance->get_instance_id(), 122 'groupid' => $instance->get_group_id() 123 ]); 124 125 $this->setUser($user); 126 127 $joinurl = $this->get_join_url($instance->get_cm_id()); 128 129 $this->assertIsArray($joinurl); 130 $this->assertArrayHasKey('join_url', $joinurl); 131 $this->assertEmpty($joinurl['warnings']); 132 $this->assertNotNull($joinurl['join_url']); 133 } 134 135 /** 136 * Check that URL are different depending on the group. 137 */ 138 public function test_execute_with_group() { 139 $this->resetAfterTest(); 140 141 $generator = $this->getDataGenerator(); 142 $course = $generator->create_course(); 143 $g1 = $generator->create_group(['courseid' => $course->id]); 144 $g2 = $generator->create_group(['courseid' => $course->id]); 145 $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]); 146 $instance = instance::get_from_instanceid($record->id); 147 148 $user = $generator->create_and_enrol($course, 'student'); 149 $bbbgenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn'); 150 // Make sure the meeting is running (this is not the default with the mock server). 151 $bbbgenerator->create_meeting([ 152 'instanceid' => $instance->get_instance_id(), 153 'groupid' => $instance->get_group_id() 154 ]); 155 156 $this->setUser($user); 157 158 $joinurlnogroup = $this->get_join_url($instance->get_cm_id()); 159 $joinurlnogroupv2 = $this->get_join_url($instance->get_cm_id()); 160 $joinurlg1 = $this->get_join_url($instance->get_cm_id(), $g1->id); 161 $joinurlg2 = $this->get_join_url($instance->get_cm_id(), $g2->id); 162 163 foreach ([$joinurlnogroup, $joinurlnogroupv2, $joinurlg1, $joinurlg2] as $join) { 164 $this->assertIsArray($join); 165 $this->assertArrayHasKey('join_url', $join); 166 $this->assertEmpty($join['warnings']); 167 $this->assertNotNull($join['join_url']); 168 } 169 $this->assertNotEquals($joinurlnogroup['join_url'], $joinurlg1['join_url']); 170 $this->assertNotEquals($joinurlg2['join_url'], $joinurlg1['join_url']); 171 } 172 173 /** 174 * Check that we return the same URL once meeting is started. 175 */ 176 public function test_execute_with_same_url() { 177 $this->resetAfterTest(); 178 179 $generator = $this->getDataGenerator(); 180 $course = $generator->create_course(); 181 $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]); 182 $instance = instance::get_from_instanceid($record->id); 183 184 $user = $generator->create_and_enrol($course, 'student'); 185 186 $bbbgenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn'); 187 // Make sure the meeting is running (this is not the default with the mock server). 188 $bbbgenerator->create_meeting([ 189 'instanceid' => $instance->get_instance_id(), 190 'groupid' => $instance->get_group_id() 191 ]); 192 193 $this->setUser($user); 194 195 $joinurl = $this->get_join_url($instance->get_cm_id()); 196 $joinurlv2 = $this->get_join_url($instance->get_cm_id()); 197 198 foreach ([$joinurl, $joinurlv2] as $join) { 199 $this->assertIsArray($join); 200 $this->assertArrayHasKey('join_url', $join); 201 $this->assertEmpty($join['warnings']); 202 $this->assertNotNull($join['join_url']); 203 } 204 $this->assertEquals($joinurl['join_url'], $joinurlv2['join_url']); 205 } 206 207 /** 208 * Check that we return the same URL once meeting is started. 209 */ 210 public function test_user_limit() { 211 $this->resetAfterTest(); 212 set_config('bigbluebuttonbn_userlimit_editable', true); 213 $generator = $this->getDataGenerator(); 214 $course = $generator->create_course(); 215 $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id, 'userlimit' => 2]); 216 217 $user1 = $generator->create_and_enrol($course, 'student'); 218 $user2 = $generator->create_and_enrol($course, 'student'); 219 $instance = instance::get_from_instanceid($record->id); 220 221 $bbbgenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn'); 222 // Make sure the meeting is running (this is not the default with the mock server). 223 $bbbgenerator->create_meeting([ 224 'instanceid' => $instance->get_instance_id(), 225 'groupid' => $instance->get_group_id(), 226 'participants' => 2 227 ]); 228 $this->setUser($user1); 229 $joinurl = $this->get_join_url($instance->get_cm_id()); 230 $this->assertNotNull($joinurl['warnings']); 231 $this->assertEquals('userlimitreached', $joinurl['warnings'][0]['warningcode']); 232 } 233 } 234
title
Description
Body
title
Description
Body
title
Description
Body
title
Body