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