Merge "Revert "Don't check namespace in SpecialWantedtemplates""
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / XmlTypeCheckTest.php
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
14
15 /**
16 * @covers XMLTypeCheck::newFromString
17 * @covers XMLTypeCheck::getRootElement
18 */
19 public function testWellFormedXML() {
20 $testXML = XmlTypeCheck::newFromString( self::WELL_FORMED_XML );
21 $this->assertTrue( $testXML->wellFormed );
22 $this->assertEquals( 'root', $testXML->getRootElement() );
23 }
24
25 /**
26 * @covers XMLTypeCheck::newFromString
27 */
28 public function testMalFormedXML() {
29 $testXML = XmlTypeCheck::newFromString( self::MAL_FORMED_XML );
30 $this->assertFalse( $testXML->wellFormed );
31 }
32
33 /**
34 * @covers XMLTypeCheck::processingInstructionHandler
35 */
36 public function testProcessingInstructionHandler() {
37 $called = false;
38 $testXML = new XmlTypeCheck(
39 self::XML_WITH_PIH,
40 null,
41 false,
42 array(
43 'processing_instruction_handler' => function() use ( &$called ) {
44 $called = true;
45 }
46 )
47 );
48 $this->assertTrue( $called );
49 }
50
51 }