Revert "MDL-40931 useragent: separated user agent functionality into a lib"
[moodle.git] / mod / scorm / tests / validatepackage_test.php
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/>.
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  */
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}.
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 basic_testcase {
40     public function test_validate_package() {
41         global $CFG;
42         $filename = "validscorm.zip";
43         $file = new zip_archive();
44         $file->open($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
45         $errors = scorm_validate_package($file);
46         $this->assertEmpty($errors);
47         $file->close();
49         $filename = "validaicc.zip";
50         $file = new zip_archive();
51         $file->open($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
52         $errors = scorm_validate_package($file);
53         $this->assertEmpty($errors);
54         $file->close();
56         $filename = "invalid.zip";
57         $file = new zip_archive();
58         $file->open($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
59         $errors = scorm_validate_package($file);
60         $this->assertArrayHasKey('packagefile', $errors);
61         if (isset($errors['packagefile'])) {
62             $this->assertEquals(get_string('nomanifest', 'scorm'), $errors['packagefile']);
63         }
64         $file->close();
66         $filename = "badscorm.zip";
67         $file = new zip_archive();
68         $file->open($CFG->dirroot.'/mod/scorm/tests/packages/'.$filename, file_archive::OPEN);
69         $errors = scorm_validate_package($file);
70         $this->assertArrayHasKey('packagefile', $errors);
71         if (isset($errors['packagefile'])) {
72             $this->assertEquals(get_string('badimsmanifestlocation', 'scorm'), $errors['packagefile']);
73         }
74         $file->close();
75     }
76 }