MDL-63660 tool_dataprivacy: Increase expected export file size
[moodle.git] / mod / scorm / tests / validatepackage_test.php
bloba27840060fd8aaf02dacaae19722c6f0ac14e724
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.
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/>.
17 /**
18 * Unit tests for the mod_quiz_display_options class.
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
27 defined('MOODLE_INTERNAL') || die();
29 global $CFG;
30 require_once($CFG->dirroot . '/mod/scorm/locallib.php');
33 /**
34 * Unit tests for {@link mod_scorm}.
36 * @copyright 2013 Dan Marsden
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class mod_scorm_validatepackage_testcase extends advanced_testcase {
41 /**
42 * Convenience to take a fixture test file and create a stored_file.
44 * @param string $filepath
45 * @return stored_file
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)
58 $fs = get_file_storage();
59 return $fs->create_file_from_pathname($filerecord, $filepath);
63 public function test_validate_package() {
64 global $CFG;
66 $this->resetAfterTest(true);
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);
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);
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']);
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']);