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 completion events.
19
 *
20
 * @package    report_completion
21
 * @copyright  2014 onwards Ankit Agarwal<ankit.agrr@gmail.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
23
 */
24
 
25
namespace report_completion\event;
26
 
27
/**
28
 * Class report_completion_events_testcase
29
 *
30
 * Class for tests related to completion report events.
31
 *
32
 * @package    report_completion
33
 * @copyright  2014 onwards Ankit Agarwal<ankit.agrr@gmail.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
        // Trigger event for completion report viewed.
57
        $event = \report_completion\event\report_viewed::create(array('context' => $context));
58
 
59
        // Trigger and capture the event.
60
        $sink = $this->redirectEvents();
61
        $event->trigger();
62
        $events = $sink->get_events();
63
        $event = reset($events);
64
 
65
        $this->assertInstanceOf('\report_completion\event\report_viewed', $event);
66
        $this->assertEquals($context, $event->get_context());
67
        $url = new \moodle_url('/report/completion/index.php', array('course' => $course->id));
68
        $this->assertEquals($url, $event->get_url());
69
        $this->assertEventContextNotUsed($event);
70
    }
71
 
72
    /**
73
     * Test the user report viewed event.
74
     *
75
     * It's not possible to use the moodle API to simulate the viewing of log 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
        $course = $this->getDataGenerator()->create_course();
80
        $context = \context_course::instance($course->id);
81
        // Trigger event for completion report viewed.
82
        $event = \report_completion\event\user_report_viewed::create(array('context' => $context, 'relateduserid' => 3));
83
 
84
        // Trigger and capture the event.
85
        $sink = $this->redirectEvents();
86
        $event->trigger();
87
        $events = $sink->get_events();
88
        $event = reset($events);
89
 
90
        $this->assertInstanceOf('\report_completion\event\user_report_viewed', $event);
91
        $this->assertEquals($context, $event->get_context());
92
        $this->assertEquals(3, $event->relateduserid);
93
        $this->assertEquals(new \moodle_url('/report/completion/user.php', array('id' => 3, 'course' => $course->id)),
94
                $event->get_url());
95
        $this->assertEventContextNotUsed($event);
96
    }
97
}