MDL-70288 qtype: Remove unnecessary empty label string
[moodle.git] / h5p / tests / event_h5p_deleted_test.php
blob89d8ca94104a24717e4a113df2783f271b2d82c6
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.
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/>.
17 /**
18 * Tests for h5p deleted event.
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
27 defined('MOODLE_INTERNAL') || die();
29 use core_h5p\local\library\autoloader;
31 /**
32 * Tests for h5p deleted event.
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
40 class core_h5p_event_h5p_deleted_testcase extends advanced_testcase {
42 /**
43 * Setup test.
45 protected function setUp(): void {
46 parent::setUp();
47 autoloader::register();
50 /**
51 * test_event_h5p_deleted description
52 * @runInSeparateProcess
54 public function test_event_h5p_deleted() {
55 $this->resetAfterTest(true);
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);
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
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']);