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