Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310]

   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   * Tests for h5p deleted event.
  19   *
  20   * @package    core_h5p
  21   * @category   test
  22   * @copyright  2019 Carlos Escobedo <carlos@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   * @since      Moodle 3.8
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use core_h5p\local\library\autoloader;
  30  
  31  /**
  32   * Tests for h5p deleted event.
  33   *
  34   * @package    core_h5p
  35   * @category   test
  36   * @copyright  2019 Carlos Escobedo <carlos@moodle.com>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   * @since      Moodle 3.8
  39   */
  40  class core_h5p_event_h5p_deleted_testcase extends advanced_testcase {
  41  
  42      /**
  43       * Setup test.
  44       */
  45      protected function setUp() {
  46          parent::setUp();
  47          autoloader::register();
  48      }
  49  
  50      /**
  51       * test_event_h5p_deleted description
  52       * @runInSeparateProcess
  53       */
  54      public function test_event_h5p_deleted() {
  55          $this->resetAfterTest(true);
  56  
  57          $user = $this->getDataGenerator()->create_user();
  58          $course = $this->getDataGenerator()->create_course();
  59          $page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
  60          $pagecontext = \context_module::instance($page->cmid);
  61  
  62          // Dummy H5P id for testing proposal. We don't need a real h5p.
  63          $dummyh5pid = 111;
  64          $now = time();
  65          // Event parameters for testing.
  66          $params = [
  67              'objectid' => $dummyh5pid,
  68              'userid' => $user->id,
  69              'context' => $pagecontext,
  70              'other' => [
  71                  'time' => $now
  72              ]
  73          ];
  74          // Prepare redirect Events.
  75          $sink = $this->redirectEvents();
  76          // Test the event H5P deleted.
  77          $event = \core_h5p\event\h5p_deleted::create($params);
  78          $event->trigger();
  79          $result = $sink->get_events();
  80          $event = reset($result);
  81          $sink->close();
  82          // Check the event info.
  83          $this->assertEquals($dummyh5pid, $event->objectid);
  84          $this->assertEquals($user->id, $event->userid);
  85          $this->assertEquals($pagecontext->id, $event->contextid);
  86          $this->assertEquals($now, $event->other['time']);
  87      }
  88  }