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 * Test xmlize xml import. 19 * 20 * @package core 21 * @category test 22 * @copyright 2017 Kilian Singer {@link http://quantumtechnology.info} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->libdir . '/xmlize.php'); 30 31 /** 32 * This test compares library against the original xmlize XML importer. 33 * 34 * @copyright 2017 Kilian Singer {@link http://quantumtechnology.info} 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class core_xmlize_testcase extends basic_testcase { 38 /** 39 * Test an XML import using a valid XML file. 40 * 41 * The test expected file was generated using the original xmlize 42 * implentation found at https://github.com/rmccue/XMLize/blob/master/xmlize-php5.inc. 43 */ 44 public function test_xmlimport_of_proper_file() { 45 $xml = file_get_contents(__DIR__ . '/sample_questions.xml'); 46 $serialised = file_get_contents(__DIR__ . '/sample_questions.ser'); 47 $this->assertEquals(unserialize($serialised), xmlize($xml)); 48 } 49 50 /** 51 * Test an XML import using invalid XML. 52 */ 53 public function test_xmlimport_of_wrong_file() { 54 $xml = file_get_contents(__DIR__ . '/sample_questions_wrong.xml'); 55 $this->expectException('xml_format_exception'); 56 $this->expectExceptionMessage('Error parsing XML: Mismatched tag at line 18, char 23'); 57 $xmlnew = xmlize($xml, 1, "UTF-8", true); 58 } 59 60 /** 61 * Test an XML import using legacy question data with old image tag. 62 */ 63 public function test_xmlimport_of_sample_question_with_old_image_tag() { 64 $xml = file_get_contents(__DIR__ . '/sample_questions_with_old_image_tag.xml'); 65 $serialised = file_get_contents(__DIR__ . '/sample_questions_with_old_image_tag.ser'); 66 67 // Compare the legacy representation in its serialized state and after unserialization. 68 $this->assertEquals($serialised, serialize(xmlize($xml))); 69 $this->assertEquals(unserialize($serialised), xmlize($xml)); 70 } 71 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body