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 core; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 global $CFG; 22 require_once($CFG->libdir . '/xmlize.php'); 23 24 /** 25 * This test compares library against the original xmlize XML importer. 26 * 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 31 */ 32 class xmlize_test extends \basic_testcase { 33 /** 34 * Test an XML import using a valid XML file. 35 * 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. 38 */ 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)); 43 } 44 45 /** 46 * Test an XML import using invalid XML. 47 */ 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); 53 } 54 55 /** 56 * Test an XML import using legacy question data with old image tag. 57 */ 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'); 61 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)); 65 } 66 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body