Proyectos de Subversion Moodle

Rev

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