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
 * File containing the SCORM module local library function tests.
19
 *
20
 * @package mod_scorm
21
 * @category test
22
 * @copyright 2017 Mark Nelson <markn@moodle.com>
23
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
namespace mod_scorm;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
global $CFG;
30
 
31
require_once($CFG->dirroot . '/mod/scorm/lib.php');
32
 
33
/**
34
 * Class containing the SCORM module local library function tests.
35
 *
36
 * @package mod_scorm
37
 * @category test
38
 * @copyright 2017 Mark Nelson <markn@moodle.com>
39
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 */
1441 ariadna 41
final class locallib_test extends \advanced_testcase {
1 efrain 42
 
43
    public function setUp(): void {
1441 ariadna 44
        parent::setUp();
1 efrain 45
        $this->resetAfterTest();
46
    }
47
 
11 efrain 48
    public function test_scorm_update_calendar(): void {
1 efrain 49
        global $DB;
50
 
51
        $this->setAdminUser();
52
 
53
        // Create a course.
54
        $course = $this->getDataGenerator()->create_course();
55
 
56
        // Create a scorm activity.
57
        $time = time();
58
        $scorm = $this->getDataGenerator()->create_module('scorm',
59
            array(
60
                'course' => $course->id,
61
                'timeopen' => $time
62
            )
63
        );
64
 
65
        // Check that there is now an event in the database.
66
        $events = $DB->get_records('event');
67
        $this->assertCount(1, $events);
68
 
69
        // Get the event.
70
        $event = reset($events);
71
 
72
        // Confirm the event is correct.
73
        $this->assertEquals('scorm', $event->modulename);
74
        $this->assertEquals($scorm->id, $event->instance);
75
        $this->assertEquals(CALENDAR_EVENT_TYPE_ACTION, $event->type);
76
        $this->assertEquals(DATA_EVENT_TYPE_OPEN, $event->eventtype);
77
        $this->assertEquals($time, $event->timestart);
78
        $this->assertEquals($time, $event->timesort);
79
    }
80
 
11 efrain 81
    public function test_scorm_update_calendar_time_open_update(): void {
1 efrain 82
        global $DB;
83
 
84
        $this->setAdminUser();
85
 
86
        // Create a course.
87
        $course = $this->getDataGenerator()->create_course();
88
 
89
        // Create a scorm activity.
90
        $time = time();
91
        $scorm = $this->getDataGenerator()->create_module('scorm',
92
            array(
93
                'course' => $course->id,
94
                'timeopen' => $time
95
            )
96
        );
97
 
98
        // Set the time open and update the event.
99
        $scorm->timeopen = $time + DAYSECS;
100
        scorm_update_calendar($scorm, $scorm->cmid);
101
 
102
        // Check that there is an event in the database.
103
        $events = $DB->get_records('event');
104
        $this->assertCount(1, $events);
105
 
106
        // Get the event.
107
        $event = reset($events);
108
 
109
        // Confirm the event time was updated.
110
        $this->assertEquals('scorm', $event->modulename);
111
        $this->assertEquals($scorm->id, $event->instance);
112
        $this->assertEquals(CALENDAR_EVENT_TYPE_ACTION, $event->type);
113
        $this->assertEquals(DATA_EVENT_TYPE_OPEN, $event->eventtype);
114
        $this->assertEquals($time + DAYSECS, $event->timestart);
115
        $this->assertEquals($time + DAYSECS, $event->timesort);
116
    }
117
 
11 efrain 118
    public function test_scorm_update_calendar_time_open_delete(): void {
1 efrain 119
        global $DB;
120
 
121
        $this->setAdminUser();
122
 
123
        // Create a course.
124
        $course = $this->getDataGenerator()->create_course();
125
 
126
        // Create a scorm activity.
127
        $scorm = $this->getDataGenerator()->create_module('scorm', array('course' => $course->id));
128
 
129
        // Create a scorm activity.
130
        $time = time();
131
        $scorm = $this->getDataGenerator()->create_module('scorm',
132
            array(
133
                'course' => $course->id,
134
                'timeopen' => $time
135
            )
136
        );
137
 
138
        // Set the time open to 0 and update the event.
139
        $scorm->timeopen = 0;
140
        scorm_update_calendar($scorm, $scorm->cmid);
141
 
142
        // Confirm the event was deleted.
143
        $this->assertEquals(0, $DB->count_records('event'));
144
    }
145
 
11 efrain 146
    public function test_scorm_update_calendar_time_close(): void {
1 efrain 147
        global $DB;
148
 
149
        $this->setAdminUser();
150
 
151
        // Create a course.
152
        $course = $this->getDataGenerator()->create_course();
153
 
154
        // Create a scorm activity.
155
        $time = time();
156
        $scorm = $this->getDataGenerator()->create_module('scorm',
157
            array(
158
                'course' => $course->id,
159
                'timeclose' => $time
160
            )
161
        );
162
 
163
        // Check that there is now an event in the database.
164
        $events = $DB->get_records('event');
165
        $this->assertCount(1, $events);
166
 
167
        // Get the event.
168
        $event = reset($events);
169
 
170
        // Confirm the event is correct.
171
        $this->assertEquals('scorm', $event->modulename);
172
        $this->assertEquals($scorm->id, $event->instance);
173
        $this->assertEquals(CALENDAR_EVENT_TYPE_ACTION, $event->type);
174
        $this->assertEquals(DATA_EVENT_TYPE_CLOSE, $event->eventtype);
175
        $this->assertEquals($time, $event->timestart);
176
        $this->assertEquals($time, $event->timesort);
177
    }
178
 
11 efrain 179
    public function test_scorm_update_calendar_time_close_update(): void {
1 efrain 180
        global $DB;
181
 
182
        $this->setAdminUser();
183
 
184
        // Create a course.
185
        $course = $this->getDataGenerator()->create_course();
186
 
187
        // Create a scorm activity.
188
        $time = time();
189
        $scorm = $this->getDataGenerator()->create_module('scorm',
190
            array(
191
                'course' => $course->id,
192
                'timeclose' => $time
193
            )
194
        );
195
 
196
        // Set the time close and update the event.
197
        $scorm->timeclose = $time + DAYSECS;
198
        scorm_update_calendar($scorm, $scorm->cmid);
199
 
200
        // Check that there is an event in the database.
201
        $events = $DB->get_records('event');
202
        $this->assertCount(1, $events);
203
 
204
        // Get the event.
205
        $event = reset($events);
206
 
207
        // Confirm the event time was updated.
208
        $this->assertEquals('scorm', $event->modulename);
209
        $this->assertEquals($scorm->id, $event->instance);
210
        $this->assertEquals(CALENDAR_EVENT_TYPE_ACTION, $event->type);
211
        $this->assertEquals(DATA_EVENT_TYPE_CLOSE, $event->eventtype);
212
        $this->assertEquals($time + DAYSECS, $event->timestart);
213
        $this->assertEquals($time + DAYSECS, $event->timesort);
214
    }
215
 
11 efrain 216
    public function test_scorm_update_calendar_time_close_delete(): void {
1 efrain 217
        global $DB;
218
 
219
        $this->setAdminUser();
220
 
221
        // Create a course.
222
        $course = $this->getDataGenerator()->create_course();
223
 
224
        // Create a scorm activity.
225
        $scorm = $this->getDataGenerator()->create_module('scorm',
226
            array(
227
                'course' => $course->id,
228
                'timeclose' => time()
229
            )
230
        );
231
 
232
        // Set the time close to 0 and update the event.
233
        $scorm->timeclose = 0;
234
        scorm_update_calendar($scorm, $scorm->cmid);
235
 
236
        // Confirm the event time was deleted.
237
        $this->assertEquals(0, $DB->count_records('event'));
238
    }
239
}