See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401]
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 namespace mod_scorm; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 global $CFG; 22 require_once($CFG->dirroot . '/mod/scorm/locallib.php'); 23 24 /** 25 * Unit tests for {@link mod_scorm}. 26 * 27 * @package mod_scorm 28 * @category test 29 * @copyright 2013 Dan Marsden 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class validatepackage_test extends \advanced_testcase { 33 34 /** 35 * Convenience to take a fixture test file and create a stored_file. 36 * 37 * @param string $filepath 38 * @return stored_file 39 */ 40 protected function create_stored_file_from_path($filepath) { 41 $syscontext = \context_system::instance(); 42 $filerecord = array( 43 'contextid' => $syscontext->id, 44 'component' => 'mod_scorm', 45 'filearea' => 'unittest', 46 'itemid' => 0, 47 'filepath' => '/', 48 'filename' => basename($filepath) 49 ); 50 51 $fs = get_file_storage(); 52 return $fs->create_file_from_pathname($filerecord, $filepath); 53 } 54 55 56 public function test_validate_package() { 57 global $CFG; 58 59 $this->resetAfterTest(true); 60 61 $filename = "validscorm.zip"; 62 $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN); 63 $errors = scorm_validate_package($file); 64 $this->assertEmpty($errors); 65 66 $filename = "validaicc.zip"; 67 $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN); 68 $errors = scorm_validate_package($file); 69 $this->assertEmpty($errors); 70 71 $filename = "invalid.zip"; 72 $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN); 73 $errors = scorm_validate_package($file); 74 $this->assertArrayHasKey('packagefile', $errors); 75 if (isset($errors['packagefile'])) { 76 $this->assertEquals(get_string('nomanifest', 'scorm'), $errors['packagefile']); 77 } 78 79 $filename = "badscorm.zip"; 80 $file = $this->create_stored_file_from_path($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, \file_archive::OPEN); 81 $errors = scorm_validate_package($file); 82 $this->assertArrayHasKey('packagefile', $errors); 83 if (isset($errors['packagefile'])) { 84 $this->assertEquals(get_string('badimsmanifestlocation', 'scorm'), $errors['packagefile']); 85 } 86 } 87 } 88
title
Description
Body
title
Description
Body
title
Description
Body
title
Body