Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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  /**
  18   * BBB Library tests class.
  19   *
  20   * @package   mod_bigbluebuttonbn
  21   * @copyright 2018 - present, Blindside Networks Inc
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   * @author    Laurent David (laurent@call-learning.fr)
  24   */
  25  namespace mod_bigbluebuttonbn\local\helpers;
  26  
  27  use core_tag_tag;
  28  use mod_bigbluebuttonbn\instance;
  29  use mod_bigbluebuttonbn\test\testcase_helper_trait;
  30  
  31  /**
  32   * BBB Library tests class.
  33   *
  34   * @package   mod_bigbluebuttonbn
  35   * @copyright 2018 - 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   * @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\reset
  39   * @covers \mod_bigbluebuttonbn\local\helpers\reset
  40   */
  41  class reset_test extends \advanced_testcase {
  42      use testcase_helper_trait;
  43      /**
  44       * Reset course item test
  45       */
  46      public function test_reset_course_items() {
  47          global $CFG;
  48          $this->resetAfterTest();
  49          $CFG->bigbluebuttonbn_recordings_enabled = false;
  50          $results = reset::reset_course_items();
  51          $this->assertEquals(["events" => 0, "tags" => 0, "logs" => 0], $results);
  52          $CFG->bigbluebuttonbn_recordings_enabled = true;
  53          $results = reset::reset_course_items();
  54          $this->assertEquals(["events" => 0, "tags" => 0, "logs" => 0, "recordings" => 0], $results);
  55      }
  56  
  57      /**
  58       * Reset get_status test
  59       */
  60      public function test_reset_getstatus() {
  61          $this->resetAfterTest();
  62          $result = reset::reset_getstatus('events');
  63          $this->assertEquals([
  64                  'component' => 'BigBlueButton',
  65                  'item' => 'Deleted events',
  66                  'error' => false,
  67          ], $result);
  68      }
  69  
  70      /**
  71       * Reset event test
  72       */
  73      public function test_reset_events() {
  74          global $DB;
  75          $this->resetAfterTest();
  76          $this->setAdminUser();
  77          list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(
  78                  null,
  79                  ['openingtime' => time()]
  80          );
  81          $formdata = $this->get_form_data_from_instance($bbactivity);
  82          \mod_bigbluebuttonbn\local\helpers\mod_helper::process_post_save($formdata);
  83          $this->assertEquals(1, $DB->count_records(
  84                  'event',
  85                  ['modulename' => 'bigbluebuttonbn', 'courseid' => $this->get_course()->id]));
  86          reset::reset_events($this->get_course()->id);
  87          $this->assertEquals(0, $DB->count_records(
  88                  'event',
  89                  ['modulename' => 'bigbluebuttonbn', 'courseid' => $this->get_course()->id]));
  90      }
  91  
  92      /**
  93       * Reset tags test
  94       */
  95      public function test_reset_tags() {
  96          $this->resetAfterTest();
  97          list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(null,
  98                  ['course' => $this->get_course()->id],
  99                  ['visible' => true]
 100          );
 101          core_tag_tag::add_item_tag('mod_bigbluebuttonbn', 'bbitem', $bbactivity->id, $bbactivitycontext, 'newtag');
 102          $alltags = core_tag_tag::get_item_tags('mod_bigbluebuttonbn', 'bbitem', $bbactivity->id);
 103          $this->assertCount(1, $alltags);
 104          reset::reset_tags($this->get_course()->id);
 105          $alltags = core_tag_tag::get_item_tags('mod_bigbluebuttonbn', 'bbitem', $bbactivity->id);
 106          $this->assertCount(0, $alltags);
 107      }
 108  
 109      /**
 110       * Reset recordings test
 111       */
 112      public function test_reset_recordings() {
 113          $this->initialise_mock_server();
 114          $this->resetAfterTest();
 115          list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(null,
 116              ['course' => $this->get_course()->id],
 117              ['visible' => true]
 118          );
 119          $instance = instance::get_from_instanceid($bbactivity->id);
 120          $this->create_recordings_for_instance($instance, [
 121              ['name' => 'Recording 1'],
 122              ['name' => 'Recording 2'],
 123          ]);
 124          $this->assertCount(2, $instance->get_recordings());
 125          reset::reset_recordings($this->get_course()->id);
 126          $this->assertCount(0, $instance->get_recordings());
 127      }
 128  }