See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [Versions 401 and 403]
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 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 update_course class. 31 * 32 * @package mod_bigbluebuttonbn 33 * @category test 34 * @copyright 2021 Andrew Lyons <andrew@nicols.co.uk> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 * @covers \mod_bigbluebuttonbn\external\can_join 37 */ 38 class can_join_test extends \externallib_advanced_testcase { 39 use testcase_helper_trait; 40 /** 41 * Setup for test 42 */ 43 public function setUp(): void { 44 parent::setUp(); 45 $this->initialise_mock_server(); 46 } 47 48 /** 49 * Helper 50 * 51 * @param mixed ...$params 52 * @return mixed 53 */ 54 protected function can_join(...$params) { 55 $canjoin = can_join::execute(...$params); 56 57 return external_api::clean_returnvalue(can_join::execute_returns(), $canjoin); 58 } 59 60 /** 61 * Test execute API CALL with no instance 62 */ 63 public function test_execute_no_instance() { 64 $canjoin = $this->can_join(1234, 5678); 65 66 $this->assertIsArray($canjoin); 67 $this->assertArrayHasKey('can_join', $canjoin); 68 $this->assertEquals(false, $canjoin['can_join']); 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(moodle_exception::class); 82 $this->can_join($instance->get_cm_id()); 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(moodle_exception::class); 100 $this->can_join($instance->get_cm_id()); 101 } 102 103 /** 104 * When login as a student 105 */ 106 public function test_execute_with_valid_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 $canjoin = $this->can_join($instance->get_cm_id()); 118 119 $this->assertIsArray($canjoin); 120 $this->assertArrayHasKey('can_join', $canjoin); 121 $this->assertEquals(true, $canjoin['can_join']); 122 } 123 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body