Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Events test.
19
 *
20
 * @package    mod_resource
21
 * @copyright  2014 Rajesh Taneja <rajesh@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_resource\event;
26
 
27
/**
28
 * Resource events test cases.
29
 *
30
 * @package    mod_resource
31
 * @copyright  2014 Rajesh Taneja <rajesh@moodle.com>
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
1441 ariadna 34
final class events_test extends \advanced_testcase {
1 efrain 35
 
36
    /**
37
     * Setup is called before calling test case.
38
     */
39
    public function setUp(): void {
1441 ariadna 40
        parent::setUp();
1 efrain 41
        $this->resetAfterTest();
42
 
43
        // Must be a non-guest user to create resources.
44
        $this->setAdminUser();
45
    }
46
 
47
    /**
48
     * Test course_module_instance_list_viewed event.
49
     */
11 efrain 50
    public function test_course_module_instance_list_viewed(): void {
1 efrain 51
        // There is no proper API to call to trigger this event, so what we are
52
        // doing here is simply making sure that the events returns the right information.
53
 
54
        $course = $this->getDataGenerator()->create_course();
55
        $params = array(
56
            'context' => \context_course::instance($course->id)
57
        );
58
        $event = \mod_resource\event\course_module_instance_list_viewed::create($params);
59
 
60
        // Triggering and capturing the event.
61
        $sink = $this->redirectEvents();
62
        $event->trigger();
63
        $events = $sink->get_events();
64
        $this->assertCount(1, $events);
65
        $event = reset($events);
66
 
67
        // Checking that the event contains the expected values.
68
        $this->assertInstanceOf('\mod_resource\event\course_module_instance_list_viewed', $event);
69
        $this->assertEquals(\context_course::instance($course->id), $event->get_context());
70
        $this->assertEventContextNotUsed($event);
71
    }
72
 
73
    /**
74
     * Test course_module_viewed event.
75
     */
11 efrain 76
    public function test_course_module_viewed(): void {
1 efrain 77
        // There is no proper API to call to trigger this event, so what we are
78
        // doing here is simply making sure that the events returns the right information.
79
 
80
        $course = $this->getDataGenerator()->create_course();
81
        $resource = $this->getDataGenerator()->create_module('resource', array('course' => $course->id));
82
 
83
        $params = array(
84
            'context' => \context_module::instance($resource->cmid),
85
            'objectid' => $resource->id
86
        );
87
        $event = \mod_resource\event\course_module_viewed::create($params);
88
 
89
        // Triggering and capturing the event.
90
        $sink = $this->redirectEvents();
91
        $event->trigger();
92
        $events = $sink->get_events();
93
        $this->assertCount(1, $events);
94
        $event = reset($events);
95
 
96
        // Checking that the event contains the expected values.
97
        $this->assertInstanceOf('\mod_resource\event\course_module_viewed', $event);
98
        $this->assertEquals(\context_module::instance($resource->cmid), $event->get_context());
99
        $this->assertEquals($resource->id, $event->objectid);
100
        $this->assertEventContextNotUsed($event);
101
    }
102
}