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   * Recording tests.
  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    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
  24   */
  25  
  26  namespace mod_bigbluebuttonbn;
  27  
  28  use mod_bigbluebuttonbn\test\testcase_helper_trait;
  29  
  30  /**
  31   * Recording test class.
  32   *
  33   * @package   mod_bigbluebuttonbn
  34   * @copyright 2018 - present, Blindside Networks Inc
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
  37   * @covers \mod_bigbluebuttonbn\recording
  38   * @coversDefaultClass \mod_bigbluebuttonbn\recording
  39   */
  40  class recording_test extends \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       * Test for bigbluebuttonbn_get_allrecordings status refresh.
  53       *
  54       * @param int $status
  55       * @dataProvider get_status_provider
  56       * @covers ::get
  57       */
  58      public function test_get_allrecordings_status_refresh(int $status) {
  59          $this->resetAfterTest();
  60          ['recordings' => $recordings] = $this->create_activity_with_recordings(
  61              $this->get_course(),
  62              instance::TYPE_ALL,
  63              [['status' => $status]]
  64          );
  65  
  66          $this->assertEquals($status, (new recording($recordings[0]->id))->get('status'));
  67      }
  68  
  69      /**
  70       * Get name
  71       *
  72       * @covers ::get_name
  73       */
  74      public function test_get_name(): void {
  75          $this->resetAfterTest();
  76          ['recordings' => $recordings] = $this->create_activity_with_recordings(
  77              $this->get_course(),
  78              instance::TYPE_ALL,
  79              [['name' => 'Example name']]
  80          );
  81  
  82          $this->assertEquals('Example name', (new recording($recordings[0]->id))->get('name'));
  83      }
  84  
  85      /**
  86       * Test get description
  87       *
  88       * @covers ::get_description
  89       */
  90      public function test_get_description(): void {
  91          $this->resetAfterTest();
  92          ['recordings' => $recordings] = $this->create_activity_with_recordings(
  93              $this->get_course(),
  94              instance::TYPE_ALL,
  95              [['description' => 'Example description']]
  96          );
  97  
  98          $this->assertEquals('Example description', (new recording($recordings[0]->id))->get('description'));
  99      }
 100  
 101      /**
 102       * Get possible status
 103       *
 104       * @return array[]
 105       */
 106      public function get_status_provider(): array {
 107          return [
 108              [recording::RECORDING_STATUS_PROCESSED],
 109              [recording::RECORDING_STATUS_DISMISSED],
 110          ];
 111      }
 112  
 113      /**
 114       * Test for bigbluebuttonbn_get_allrecordings()
 115       *
 116       * @param int $type The activity type
 117       * @dataProvider get_allrecordings_types_provider
 118       * @covers ::get_recordings_for_instance
 119       */
 120      public function test_get_allrecordings(int $type): void {
 121          $this->resetAfterTest();
 122          $recordingcount = 2; // Two recordings only.
 123          ['activity' => $activity] = $this->create_activity_with_recordings(
 124              $this->get_course(),
 125              $type,
 126              array_pad([], $recordingcount, [])
 127          );
 128  
 129          // Fetch the recordings for the instance.
 130          // The count shoudl match the input count.
 131          $recordings = recording::get_recordings_for_instance(instance::get_from_instanceid($activity->id));
 132          $this->assertCount($recordingcount, $recordings);
 133      }
 134  
 135      /**
 136       * Get possible type for recording / tests
 137       *
 138       * @return array[]
 139       */
 140      public function get_allrecordings_types_provider(): array {
 141          return [
 142              'Instance Type ALL' => [
 143                  'type' => instance::TYPE_ALL
 144              ],
 145              'Instance Type ROOM Only' => [
 146                  'type' => instance::TYPE_ROOM_ONLY,
 147              ],
 148              'Instance Type Recording only' => [
 149                  'type' => instance::TYPE_RECORDING_ONLY
 150              ],
 151          ];
 152      }
 153  
 154      /**
 155       * Test for bigbluebuttonbn_get_allrecordings().
 156       *
 157       * @param int $type
 158       * @dataProvider get_allrecordings_types_provider
 159       */
 160      public function test_get_recording_for_group($type) {
 161          $this->resetAfterTest();
 162  
 163          $plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
 164  
 165          $testcourse = $this->getDataGenerator()->create_course(['groupmodeforce' => true, 'groupmode' => VISIBLEGROUPS]);
 166          $teacher = $this->getDataGenerator()->create_and_enrol($testcourse, 'editingteacher');
 167  
 168          $group1 = $this->getDataGenerator()->create_group(['G1', 'courseid' => $testcourse->id]);
 169          $student1 = $this->getDataGenerator()->create_and_enrol($testcourse);
 170          $this->getDataGenerator()->create_group_member(['userid' => $student1, 'groupid' => $group1->id]);
 171  
 172          $group2 = $this->getDataGenerator()->create_group(['G2', 'courseid' => $testcourse->id]);
 173          $student2 = $this->getDataGenerator()->create_and_enrol($testcourse);
 174          $this->getDataGenerator()->create_group_member(['userid' => $student2, 'groupid' => $group2->id]);
 175  
 176          // No group.
 177          $student3 = $this->getDataGenerator()->create_and_enrol($testcourse);
 178  
 179          $activity = $plugingenerator->create_instance([
 180              'course' => $testcourse->id,
 181              'type' => $type,
 182              'name' => 'Example'
 183          ]);
 184          $instance = instance::get_from_instanceid($activity->id);
 185          $instance->set_group_id(0);
 186          $this->create_recordings_for_instance($instance, [['name' => "Pre-Recording 1"], ['name' => "Pre-Recording 2"]]);
 187          $instance->set_group_id($group1->id);
 188          $this->create_recordings_for_instance($instance, [['name' => "Group 1 Recording 1"]]);
 189          $instance->set_group_id($group2->id);
 190          $this->create_recordings_for_instance($instance, [['name' => "Group 2 Recording 1"]]);
 191  
 192          $this->setUser($student1);
 193          $instance1 = instance::get_from_instanceid($activity->id);
 194          $instance1->set_group_id($group1->id);
 195          $recordings = recording::get_recordings_for_instance($instance1);
 196          $this->assertCount(1, $recordings);
 197          $this->assert_has_recording_by_name('Group 1 Recording 1', $recordings);
 198  
 199          $this->setUser($student2);
 200          $instance2 = instance::get_from_instanceid($activity->id);
 201          $instance2->set_group_id($group2->id);
 202          $recordings = recording::get_recordings_for_instance($instance2);
 203          $this->assertCount(1, $recordings);
 204          $this->assert_has_recording_by_name('Group 2 Recording 1', $recordings);
 205  
 206          $this->setUser($student3);
 207          $instance3 = instance::get_from_instanceid($activity->id);
 208          $recordings = recording::get_recordings_for_instance($instance3);
 209          $this->assertIsArray($recordings);
 210          $this->assertCount(4, $recordings);
 211          $this->assert_has_recording_by_name('Pre-Recording 1', $recordings);
 212          $this->assert_has_recording_by_name('Pre-Recording 2', $recordings);
 213      }
 214  
 215      /**
 216       * Test that we can get recordings from a deleted activity
 217       *
 218       * @param int $type
 219       * @dataProvider get_allrecordings_types_provider
 220       */
 221      public function test_get_recordings_from_deleted_activity($type) {
 222          $this->resetAfterTest(true);
 223          $this->initialise_mock_server();
 224          $plugingenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
 225  
 226          $testcourse = $this->getDataGenerator()->create_course();
 227  
 228          $activity = $plugingenerator->create_instance([
 229              'course' => $testcourse->id,
 230              'type' => $type,
 231              'name' => 'Example'
 232          ]);
 233          $instance = instance::get_from_instanceid($activity->id);
 234          $this->create_recordings_for_instance($instance, [['name' => "Deleted Recording 1"]]);
 235          $activity2 = $plugingenerator->create_instance([
 236              'course' => $testcourse->id,
 237              'type' => $type,
 238              'name' => 'Example'
 239          ]);
 240          $instance2 = instance::get_from_instanceid($activity2->id);
 241          $this->create_recordings_for_instance($instance2, [['name' => "Recording 1"]]);
 242  
 243          bigbluebuttonbn_delete_instance($activity->id);
 244          $recordings = recording::get_recordings_for_course($testcourse->id, [], false, false, true);
 245          $this->assertCount(2, $recordings);
 246          $this->assert_has_recording_by_name('Deleted Recording 1', $recordings);
 247          $this->assert_has_recording_by_name('Recording 1', $recordings);
 248          $recordings = recording::get_recordings_for_course($testcourse->id, [], false, false, false);
 249          $this->assertCount(1, $recordings);
 250      }
 251  
 252      /**
 253       * Check that a recording exist in the list of recordings
 254       *
 255       * @param string $recordingname
 256       * @param array $recordings
 257       */
 258      public function assert_has_recording_by_name($recordingname, $recordings) {
 259          $recordingnames = array_map(function ($r) {
 260              return $r->get('name');
 261          }, $recordings);
 262          $this->assertContains($recordingname, $recordingnames);
 263      }
 264  
 265      /**
 266       * Simple recording with breakoutroom fetcher test
 267       *
 268       * @return void
 269       */
 270      public function test_recordings_breakoutroom() {
 271          $this->resetAfterTest();
 272          $this->initialise_mock_server();
 273          [$context, $cm, $bbbactivity] = $this->create_instance();
 274          $instance = instance::get_from_instanceid($bbbactivity->id);
 275          $bbbgenerator = $this->getDataGenerator()->get_plugin_generator('mod_bigbluebuttonbn');
 276          $mainmeeting = $bbbgenerator->create_meeting([
 277              'instanceid' => $instance->get_instance_id(),
 278              'groupid' => $instance->get_group_id(),
 279          ]);
 280          // This creates a meeting to receive the recordings (specific to the mock server implementation). See recording_proxy_test.
 281          $bbbgenerator->create_meeting([
 282              'instanceid' => $instance->get_instance_id(),
 283              'groupid' => $instance->get_group_id(),
 284              'isBreakout' => true,
 285              'sequence' => 1
 286          ]);
 287          $bbbgenerator->create_meeting([
 288              'instanceid' => $instance->get_instance_id(),
 289              'groupid' => $instance->get_group_id(),
 290              'isBreakout' => true,
 291              'sequence' => 2
 292          ]);
 293          // For now only recording from the main room have been created.
 294          $this->create_recordings_for_instance($instance, [
 295              ['name' => 'Recording 1'],
 296          ]);
 297          $recordings = recording::get_recordings_for_instance($instance);
 298          $this->assertCount(1, $recordings);
 299  
 300          // Now the breakoutroom recordings appears.
 301          $this->create_recordings_for_instance($instance, [
 302              ['name' => 'Recording 2', 'isBreakout' => true, 'sequence' => 1],
 303              ['name' => 'Recording 3', 'isBreakout' => true, 'sequence' => 2]
 304          ]);
 305          $recordings = recording::get_recordings_for_instance($instance);
 306          $this->assertCount(3, $recordings);
 307      }
 308  }