Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 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  use require_login_exception;
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  require_once($CFG->dirroot . '/webservice/tests/helpers.php');
  29  
  30  /**
  31   * Tests for the view_bigbluebuttonbn class.
  32   *
  33   * @package    mod_bigbluebuttonbn
  34   * @category   test
  35   * @copyright  2021 - present, Blindside Networks Inc
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   * @author    Laurent David (laurent@call-learning.fr)
  38   * @covers \mod_bigbluebuttonbn\external\view_bigbluebuttonbn
  39   */
  40  class view_bigbluebuttonbn_test extends \externallib_advanced_testcase {
  41      use testcase_helper_trait;
  42  
  43      /**
  44       * Setup for test
  45       */
  46      public function setUp(): void {
  47          parent::setUp();
  48          $this->initialise_mock_server();
  49      }
  50  
  51      /**
  52       * Helper
  53       *
  54       * @param mixed ...$params
  55       * @return mixed
  56       */
  57      protected function view_bigbluebuttonbn(...$params) {
  58          $returnvalue = view_bigbluebuttonbn::execute(...$params);
  59  
  60          return external_api::clean_returnvalue(view_bigbluebuttonbn::execute_returns(), $returnvalue);
  61      }
  62  
  63      /**
  64       * Test execute API CALL with no instance
  65       */
  66      public function test_execute_no_instance() {
  67          $bbbactivities = $this->view_bigbluebuttonbn(1234);
  68  
  69          $this->assertIsArray($bbbactivities);
  70          $this->assertArrayHasKey('status', $bbbactivities);
  71          $this->assertArrayHasKey('warnings', $bbbactivities);
  72          $this->assertFalse($bbbactivities['status']);
  73      }
  74  
  75      /**
  76       * Test execute API CALL without login
  77       */
  78      public function test_execute_without_login() {
  79          $this->resetAfterTest();
  80  
  81          $course = $this->getDataGenerator()->create_course();
  82          $record = $this->getDataGenerator()->create_module('bigbluebuttonbn', ['course' => $course->id]);
  83          $instance = instance::get_from_instanceid($record->id);
  84          $this->expectException(require_login_exception::class);
  85          $this->view_bigbluebuttonbn($instance->get_instance_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($course);
 100          $this->setUser($user);
 101          $this->expectException(require_login_exception::class);
 102          $this->view_bigbluebuttonbn($instance->get_instance_id());
 103      }
 104  
 105      /**
 106       * When login as a student
 107       */
 108      public function test_execute_with_valid_login() {
 109          $this->resetAfterTest();
 110  
 111          $generator = $this->getDataGenerator();
 112          $course = $generator->create_course();
 113          $record = $generator->create_module('bigbluebuttonbn', ['course' => $course->id]);
 114          $instance = instance::get_from_instanceid($record->id);
 115  
 116          $user = $generator->create_and_enrol($course, 'student');
 117          $this->setUser($user);
 118  
 119          $returnvalue = $this->view_bigbluebuttonbn($instance->get_instance_id());
 120  
 121          $this->assertArrayHasKey('status', $returnvalue);
 122          $this->assertArrayHasKey('warnings', $returnvalue);
 123          $this->assertTrue($returnvalue['status']);
 124      }
 125  }
 126