Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / tests / phpunit / includes / libs / XmlTypeCheckTest.php
blob7f9a772aa71329d119bd086d0780baf183d473e7
1 <?php
2 /**
3 * PHPUnit tests for XMLTypeCheck.
4 * @author physikerwelt
5 * @group Xml
6 * @covers XMLTypeCheck
7 */
8 class XmlTypeCheckTest extends PHPUnit_Framework_TestCase {
9 const WELL_FORMED_XML = "<root><child /></root>";
10 const MAL_FORMED_XML = "<root><child /></error>";
11 // @codingStandardsIgnoreStart Generic.Files.LineLength
12 const XML_WITH_PIH = '<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/w/index.php"?><svg><child /></svg>';
13 // @codingStandardsIgnoreEnd
15 /**
16 * @covers XMLTypeCheck::newFromString
17 * @covers XMLTypeCheck::getRootElement
19 public function testWellFormedXML() {
20 $testXML = XmlTypeCheck::newFromString( self::WELL_FORMED_XML );
21 $this->assertTrue( $testXML->wellFormed );
22 $this->assertEquals( 'root', $testXML->getRootElement() );
25 /**
26 * @covers XMLTypeCheck::newFromString
28 public function testMalFormedXML() {
29 $testXML = XmlTypeCheck::newFromString( self::MAL_FORMED_XML );
30 $this->assertFalse( $testXML->wellFormed );
33 /**
34 * Verify we check for recursive entity DOS
36 * (If the DOS isn't properly handled, the test runner will probably go OOM...)
38 public function testRecursiveEntity() {
39 $xml = <<<'XML'
40 <?xml version="1.0" encoding="utf-8"?>
41 <!DOCTYPE foo [
42 <!ENTITY test "&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;">
43 <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
44 <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
45 <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
46 <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;">
47 <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;">
48 <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;">
49 <!ENTITY g "-00000000000000000000000000000000000000000000000000000000000000000000000-">
51 <foo>
52 <bar>&test;</bar>
53 </foo>
54 XML;
55 $check = XmlTypeCheck::newFromString( $xml );
56 $this->assertFalse( $check->wellFormed );
59 /**
60 * @covers XMLTypeCheck::processingInstructionHandler
62 public function testProcessingInstructionHandler() {
63 $called = false;
64 $testXML = new XmlTypeCheck(
65 self::XML_WITH_PIH,
66 null,
67 false,
69 'processing_instruction_handler' => function() use ( &$called ) {
70 $called = true;
74 $this->assertTrue( $called );