PortableInfobox/tests/phpunit/XmlParserTest.php
2021-12-15 15:01:13 -07:00

45 lines
1.2 KiB
PHP

<?php
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\XmlParser
*/
class XmlParserTest extends MediaWikiIntegrationTestCase {
/** @dataProvider contentTagsDataProvider */
public function testXHTMLParsing( $tag, $content ) {
$markup = "<data source=\"asdfd\"><{$tag}>{$content}</{$tag}></data>";
$result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
$this->assertEquals( $content, (string)$result->{$tag} );
}
public function contentTagsDataProvider() {
return [
[ 'default', 'sadf <br> sakdjfl' ],
[ 'format', '<>' ],
[ 'label', '' ]
];
}
/**
* @dataProvider entitiesTestDataProvider
*/
public function testHTMLEntities( $markup, $expectedResult ) {
$result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
$this->assertEquals( $expectedResult, $result[ 0 ] );
}
public function entitiesTestDataProvider() {
return [
[ '<data></data>', '' ],
[ '<data>&aksjdf;</data>', '&aksjdf;' ],
[ '<data>&amp;</data>', '&' ],
[ '<data>&middot;</data>', '·' ],
[ '<data>&Uuml;</data>', 'Ü' ],
[ '<data>&Delta;</data>', 'Δ' ],
[ '<data>&amp;amp;</data>', '&amp;' ],
[ '<data>&amp</data>', '&amp' ]
];
}
}