Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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  namespace core_h5p\event;
  18  
  19  use core_h5p\local\library\autoloader;
  20  
  21  /**
  22   * Tests for h5p deleted event.
  23   *
  24   * @package    core_h5p
  25   * @category   test
  26   * @copyright  2019 Carlos Escobedo <carlos@moodle.com>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   * @since      Moodle 3.8
  29   */
  30  class deleted_test extends \advanced_testcase {
  31  
  32      /**
  33       * Setup test.
  34       */
  35      protected function setUp(): void {
  36          parent::setUp();
  37          autoloader::register();
  38      }
  39  
  40      /**
  41       * test_event_h5p_deleted description
  42       * @runInSeparateProcess
  43       */
  44      public function test_event_h5p_deleted() {
  45          $this->resetAfterTest(true);
  46  
  47          $user = $this->getDataGenerator()->create_user();
  48          $course = $this->getDataGenerator()->create_course();
  49          $page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
  50          $pagecontext = \context_module::instance($page->cmid);
  51  
  52          // Dummy H5P id for testing proposal. We don't need a real h5p.
  53          $dummyh5pid = 111;
  54          $now = time();
  55          // Event parameters for testing.
  56          $params = [
  57              'objectid' => $dummyh5pid,
  58              'userid' => $user->id,
  59              'context' => $pagecontext,
  60              'other' => [
  61                  'time' => $now
  62              ]
  63          ];
  64          // Prepare redirect Events.
  65          $sink = $this->redirectEvents();
  66          // Test the event H5P deleted.
  67          $event = h5p_deleted::create($params);
  68          $event->trigger();
  69          $result = $sink->get_events();
  70          $event = reset($result);
  71          $sink->close();
  72          // Check the event info.
  73          $this->assertEquals($dummyh5pid, $event->objectid);
  74          $this->assertEquals($user->id, $event->userid);
  75          $this->assertEquals($pagecontext->id, $event->contextid);
  76          $this->assertEquals($now, $event->other['time']);
  77      }
  78  }