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 401] [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\task;
  18  
  19  use advanced_testcase;
  20  
  21  /**
  22   * Class containing the scheduled task for lti module.
  23   *
  24   * @package   mod_bigbluebuttonbn
  25   * @copyright 2019 onwards, Blindside Networks Inc
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   * @coversDefaultClass \mod_bigbluebuttonbn\task\send_notification
  28   * @covers \mod_bigbluebuttonbn\task\send_notification
  29   * @covers \mod_bigbluebuttonbn\task\send_recording_ready_notification
  30   */
  31  class send_recording_ready_notification_test extends advanced_testcase {
  32      /**
  33       * Test the sending of messages.
  34       */
  35      public function test_recipients(): void {
  36          $this->resetAfterTest();
  37          $this->preventResetByRollback();
  38  
  39          $generator = $this->getDataGenerator();
  40          $course = $generator->create_course();
  41          $instancedata = $generator->create_module('bigbluebuttonbn', [
  42              'course' => $course->id,
  43          ]);
  44  
  45          // Create some users in the course, and some not.
  46          $editingteacher = $generator->create_and_enrol($course, 'editingteacher');
  47          $teacher = $generator->create_and_enrol($course, 'teacher');
  48          $students = [
  49              $generator->create_and_enrol($course, 'student'),
  50              $generator->create_and_enrol($course, 'student'),
  51              $generator->create_and_enrol($course, 'student'),
  52              $generator->create_and_enrol($course, 'student'),
  53              $generator->create_and_enrol($course, 'student'),
  54          ];
  55  
  56          $recipients = array_map(function($user) {
  57              return $user->id;
  58          }, $students);
  59          $recipients[] = $editingteacher->id;
  60          $recipients[] = $teacher->id;
  61  
  62          $unrelateduser = $generator->create_user();
  63  
  64          $instancedata = $generator->create_module('bigbluebuttonbn', [
  65              'course' => $course->id,
  66          ]);
  67  
  68          $stub = $this->getMockBuilder(send_recording_ready_notification::class)
  69              ->onlyMethods([])
  70              ->getMock();
  71  
  72          $stub->set_instance_id($instancedata->id);
  73  
  74          // Capture events.
  75          $sink = $this->redirectMessages();
  76  
  77          // Now execute.
  78          $stub->execute();
  79  
  80          // Check the events.
  81          $messages = $sink->get_messages();
  82          $this->assertCount(7, $messages);
  83  
  84          foreach ($messages as $message) {
  85              $this->assertNotFalse(array_search($message->useridto, $recipients));
  86              $this->assertNotEquals($unrelateduser->id, $message->useridto);
  87              $this->assertEquals($editingteacher->id, $message->useridfrom);
  88          }
  89      }
  90  
  91      /**
  92       * Test the sending of messages.
  93       */
  94      public function test_recipients_no_teacher(): void {
  95          $this->resetAfterTest();
  96          $this->preventResetByRollback();
  97  
  98          $generator = $this->getDataGenerator();
  99          $course = $generator->create_course();
 100          $instancedata = $generator->create_module('bigbluebuttonbn', [
 101              'course' => $course->id,
 102          ]);
 103  
 104          // Create some users in the course, and some not.
 105          $students = [
 106              $generator->create_and_enrol($course, 'student'),
 107              $generator->create_and_enrol($course, 'student'),
 108              $generator->create_and_enrol($course, 'student'),
 109              $generator->create_and_enrol($course, 'student'),
 110              $generator->create_and_enrol($course, 'student'),
 111          ];
 112  
 113          $recipients = array_map(function($user) {
 114              return $user->id;
 115          }, $students);
 116  
 117          $unrelateduser = $generator->create_user();
 118  
 119          $instancedata = $generator->create_module('bigbluebuttonbn', [
 120              'course' => $course->id,
 121          ]);
 122  
 123          $stub = $this->getMockBuilder(send_recording_ready_notification::class)
 124              ->onlyMethods([])
 125              ->getMock();
 126  
 127          $stub->set_instance_id($instancedata->id);
 128  
 129          // Capture events.
 130          $sink = $this->redirectMessages();
 131  
 132          // Now execute.
 133          $stub->execute();
 134  
 135          // Check the events.
 136          $messages = $sink->get_messages();
 137          $this->assertCount(5, $messages);
 138  
 139          $noreplyuser = \core_user::get_noreply_user();
 140          foreach ($messages as $message) {
 141              $this->assertNotFalse(array_search($message->useridto, $recipients));
 142              $this->assertNotEquals($unrelateduser->id, $message->useridto);
 143              $this->assertEquals($noreplyuser->id, $message->useridfrom);
 144          }
 145      }
 146  
 147      /**
 148       * Test that messages are not sent to a suspended user.
 149       */
 150      public function test_messages_sent_suspended_user(): void {
 151          global $DB;
 152  
 153          $this->resetAfterTest();
 154          $this->preventResetByRollback();
 155  
 156          $generator = $this->getDataGenerator();
 157          $course = $generator->create_course();
 158          $instancedata = $generator->create_module('bigbluebuttonbn', [
 159              'course' => $course->id,
 160          ]);
 161  
 162          // Create some users in the course, and some not.
 163          $student = $generator->create_and_enrol($course, 'student');
 164          $suspendedstudent = $generator->create_and_enrol($course, 'student');
 165          $DB->set_field('user', 'suspended', 1, ['id' => $suspendedstudent->id]);
 166  
 167          $instancedata = $generator->create_module('bigbluebuttonbn', [
 168              'course' => $course->id,
 169          ]);
 170  
 171          $stub = $this->getMockBuilder(send_recording_ready_notification::class)
 172              ->onlyMethods([])
 173              ->getMock();
 174  
 175          $stub->set_instance_id($instancedata->id);
 176  
 177          // Capture events.
 178          $sink = $this->redirectMessages();
 179  
 180          // Now execute.
 181          $stub->execute();
 182  
 183          // Check the events.
 184          $messages = $sink->get_messages();
 185          $this->assertCount(1, $messages);
 186  
 187          $noreplyuser = \core_user::get_noreply_user();
 188          foreach ($messages as $message) {
 189              $this->assertEquals($student->id, $message->useridto);
 190              $this->assertNotEquals($suspendedstudent->id, $message->useridto);
 191              $this->assertEquals($noreplyuser->id, $message->useridfrom);
 192          }
 193      }
 194  }