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