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
 * Tests for report log events.
19
 *
20
 * @package    report_log
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 report_log\event;
26
 
27
/**
28
 * Class report_log_events_testcase
29
 *
30
 * Class for tests related to log events.
31
 *
32
 * @package    report_log
33
 * @copyright  2014 Rajesh Taneja <rajesh@moodle.com>
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
35
 */
1441 ariadna 36
final class events_test extends \advanced_testcase {
1 efrain 37
 
38
    /**
39
     * Setup testcase.
40
     */
41
    public function setUp(): void {
1441 ariadna 42
        parent::setUp();
1 efrain 43
        $this->setAdminUser();
44
        $this->resetAfterTest();
45
    }
46
 
47
    /**
48
     * Test the report viewed event.
49
     *
50
     * It's not possible to use the moodle API to simulate the viewing of log report, so here we
51
     * simply create the event and trigger it.
52
     */
11 efrain 53
    public function test_report_viewed(): void {
1 efrain 54
        $course = $this->getDataGenerator()->create_course();
55
        $context = \context_course::instance($course->id);
56
 
57
        // Trigger event for log report viewed.
58
        $event = \report_log\event\report_viewed::create(array('context' => $context,
59
                'relateduserid' => 0, 'other' => array('groupid' => 0, 'date' => 0, 'modid' => 0, 'modaction' => '',
60
                'logformat' => 'showashtml')));
61
 
62
        // Trigger and capture the event.
63
        $sink = $this->redirectEvents();
64
        $event->trigger();
65
        $events = $sink->get_events();
66
        $event = reset($events);
67
 
68
        $this->assertInstanceOf('\report_log\event\report_viewed', $event);
69
        $this->assertEquals($context, $event->get_context());
70
        $this->assertEventContextNotUsed($event);
71
        $url = new \moodle_url('/report/log/index.php', array('id' => $event->courseid));
72
        $this->assertEquals($url, $event->get_url());
73
    }
74
 
75
    /**
76
     * Test the user report viewed event.
77
     *
78
     * It's not possible to use the moodle API to simulate the viewing of user log report, so here we
79
     * simply create the event and trigger it.
80
     */
11 efrain 81
    public function test_user_report_viewed(): void {
1 efrain 82
        $user = $this->getDataGenerator()->create_user();
83
        $course = $this->getDataGenerator()->create_course();
84
        $context = \context_course::instance($course->id);
85
 
86
        // Trigger event for user report viewed.
87
        $event = \report_log\event\user_report_viewed::create(array('context' => $context,
88
                'relateduserid' => $user->id, 'other' => array('mode' => 'today')));
89
 
90
        // Trigger and capture the event.
91
        $sink = $this->redirectEvents();
92
        $event->trigger();
93
        $events = $sink->get_events();
94
        $event = reset($events);
95
 
96
        $this->assertInstanceOf('\report_log\event\user_report_viewed', $event);
97
        $this->assertEquals($context, $event->get_context());
98
        $this->assertEventContextNotUsed($event);
99
        $url = new \moodle_url('/report/log/user.php', array('course' => $course->id, 'id' => $user->id, 'mode' => 'today'));
100
        $this->assertEquals($url, $event->get_url());
101
    }
102
}