Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [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 core_external\external_api;
  20  use mod_bigbluebuttonbn\instance;
  21  use mod_bigbluebuttonbn\test\testcase_helper_trait;
  22  use require_login_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 view_bigbluebuttonbn 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\view_bigbluebuttonbn
  38   */
  39  class view_bigbluebuttonbn_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 view_bigbluebuttonbn(...$params) {
  57          $returnvalue = view_bigbluebuttonbn::execute(...$params);
  58  
  59          return external_api::clean_returnvalue(view_bigbluebuttonbn::execute_returns(), $returnvalue);
  60      }
  61  
  62      /**
  63       * Test execute API CALL with no instance
  64       */
  65      public function test_execute_no_instance() {
  66          $bbbactivities = $this->view_bigbluebuttonbn(1234);
  67  
  68          $this->assertIsArray($bbbactivities);
  69          $this->assertArrayHasKey('status', $bbbactivities);
  70          $this->assertArrayHasKey('warnings', $bbbactivities);
  71          $this->assertFalse($bbbactivities['status']);
  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          $this->expectException(require_login_exception::class);
  84          $this->view_bigbluebuttonbn($instance->get_instance_id());
  85      }
  86  
  87      /**
  88       * Test execute API CALL with invalid login
  89       */
  90      public function test_execute_with_invalid_login() {
  91          $this->resetAfterTest();
  92  
  93          $generator = $this->getDataGenerator();
  94          $course = $generator->create_course();
  95          $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
  96          $instance = instance::get_from_instanceid($record->id);
  97  
  98          $user = $generator->create_user($course);
  99          $this->setUser($user);
 100          $this->expectException(require_login_exception::class);
 101          $this->view_bigbluebuttonbn($instance->get_instance_id());
 102      }
 103  
 104      /**
 105       * When login as a student
 106       */
 107      public function test_execute_with_valid_login() {
 108          $this->resetAfterTest();
 109  
 110          $generator = $this->getDataGenerator();
 111          $course = $generator->create_course();
 112          $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
 113          $instance = instance::get_from_instanceid($record->id);
 114  
 115          $user = $generator->create_and_enrol($course, 'student');
 116          $this->setUser($user);
 117  
 118          $returnvalue = $this->view_bigbluebuttonbn($instance->get_instance_id());
 119  
 120          $this->assertArrayHasKey('status', $returnvalue);
 121          $this->assertArrayHasKey('warnings', $returnvalue);
 122          $this->assertTrue($returnvalue['status']);
 123      }
 124  }
 125