MDL-79059 core: Use full name as alt text for user picture links
[moodle.git] / lib / tests / xmlize_test.php
blobcfdfb33be72c7e2e2729626149b368812bb1dcda
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 namespace core;
19 defined('MOODLE_INTERNAL') || die();
21 global $CFG;
22 require_once($CFG->libdir . '/xmlize.php');
24 /**
25 * This test compares library against the original xmlize XML importer.
27 * @package core
28 * @category test
29 * @copyright 2017 Kilian Singer {@link http://quantumtechnology.info}
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class xmlize_test extends \basic_testcase {
33 /**
34 * Test an XML import using a valid XML file.
36 * The test expected file was generated using the original xmlize
37 * implentation found at https://github.com/rmccue/XMLize/blob/master/xmlize-php5.inc.
39 public function test_xmlimport_of_proper_file() {
40 $xml = file_get_contents(__DIR__ . '/sample_questions.xml');
41 $serialised = file_get_contents(__DIR__ . '/sample_questions.ser');
42 $this->assertEquals(unserialize($serialised), xmlize($xml));
45 /**
46 * Test an XML import using invalid XML.
48 public function test_xmlimport_of_wrong_file() {
49 $xml = file_get_contents(__DIR__ . '/sample_questions_wrong.xml');
50 $this->expectException('xml_format_exception');
51 $this->expectExceptionMessage('Error parsing XML: Mismatched tag at line 18, char 23');
52 $xmlnew = xmlize($xml, 1, "UTF-8", true);
55 /**
56 * Test an XML import using legacy question data with old image tag.
58 public function test_xmlimport_of_sample_question_with_old_image_tag() {
59 $xml = file_get_contents(__DIR__ . '/sample_questions_with_old_image_tag.xml');
60 $serialised = file_get_contents(__DIR__ . '/sample_questions_with_old_image_tag.ser');
62 // Compare the legacy representation in its serialized state and after unserialization.
63 $this->assertEquals($serialised, serialize(xmlize($xml)));
64 $this->assertEquals(unserialize($serialised), xmlize($xml));