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
 * Events tests.
19
 *
20
 * @package    mod_survey
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_survey\event;
26
 
27
/**
28
 * Events tests class.
29
 *
30
 * @package    mod_survey
31
 * @copyright  2014 Rajesh Taneja <rajesh@moodle.com>
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class events_test extends \advanced_testcase {
35
 
36
    /**
37
     * Setup.
38
     */
39
    public function setUp(): void {
40
        $this->resetAfterTest();
41
        // Survey module is disabled by default, enable it for testing.
42
        $manager = \core_plugin_manager::resolve_plugininfo_class('mod');
43
        $manager::enable_plugin('survey', 1);
44
    }
45
 
46
    /**
47
     * Test report downloaded event.
48
     */
11 efrain 49
    public function test_report_downloaded(): void {
1 efrain 50
        // There is no proper API to call to generate chapters for a book, so what we are
51
        // doing here is simply making sure that the events returns the right information.
52
 
53
        $course = $this->getDataGenerator()->create_course();
54
        $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id));
55
 
56
        $params = array(
57
            'objectid' => $survey->id,
58
            'context' => \context_module::instance($survey->cmid),
59
            'courseid' => $course->id,
60
            'other' => array('type' => 'xls')
61
        );
62
        $event = \mod_survey\event\report_downloaded::create($params);
63
 
64
        // Triggering and capturing the event.
65
        $sink = $this->redirectEvents();
66
        $event->trigger();
67
        $events = $sink->get_events();
68
        $this->assertCount(1, $events);
69
        $event = reset($events);
70
 
71
        // Checking that the event contains the expected values.
72
        $this->assertInstanceOf('\mod_survey\event\report_downloaded', $event);
73
        $this->assertEquals(\context_module::instance($survey->cmid), $event->get_context());
74
        $this->assertEquals($survey->id, $event->objectid);
75
        $this->assertEventContextNotUsed($event);
76
    }
77
 
78
    /**
79
     * Test report viewed event.
80
     */
11 efrain 81
    public function test_report_viewed(): void {
1 efrain 82
        // There is no proper API to call to generate chapters for a book, so what we are
83
        // doing here is simply making sure that the events returns the right information.
84
 
85
        $course = $this->getDataGenerator()->create_course();
86
        $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id));
87
 
88
        $params = array(
89
            'objectid' => $survey->id,
90
            'context' => \context_module::instance($survey->cmid),
91
            'courseid' => $course->id
92
        );
93
        $event = \mod_survey\event\report_viewed::create($params);
94
 
95
        // Triggering and capturing the event.
96
        $sink = $this->redirectEvents();
97
        $event->trigger();
98
        $events = $sink->get_events();
99
        $this->assertCount(1, $events);
100
        $event = reset($events);
101
 
102
        // Checking that the event contains the expected values.
103
        $this->assertInstanceOf('\mod_survey\event\report_viewed', $event);
104
        $this->assertEquals(\context_module::instance($survey->cmid), $event->get_context());
105
        $this->assertEquals($survey->id, $event->objectid);
106
    }
107
 
108
    /**
109
     * Test response submitted event.
110
     */
11 efrain 111
    public function test_response_submitted(): void {
1 efrain 112
        // There is no proper API to call to generate chapters for a book, so what we are
113
        // doing here is simply making sure that the events returns the right information.
114
 
115
        $course = $this->getDataGenerator()->create_course();
116
        $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id));
117
 
118
        $params = array(
119
            'context' => \context_module::instance($survey->cmid),
120
            'courseid' => $course->id,
121
            'other' => array('surveyid' => $survey->id)
122
        );
123
        $event = \mod_survey\event\response_submitted::create($params);
124
 
125
        // Triggering and capturing the event.
126
        $sink = $this->redirectEvents();
127
        $event->trigger();
128
        $events = $sink->get_events();
129
        $this->assertCount(1, $events);
130
        $event = reset($events);
131
 
132
        // Checking that the event contains the expected values.
133
        $this->assertInstanceOf('\mod_survey\event\response_submitted', $event);
134
        $this->assertEquals(\context_module::instance($survey->cmid), $event->get_context());
135
        $this->assertEquals($survey->id, $event->other['surveyid']);
136
        $this->assertEventContextNotUsed($event);
137
    }
138
}