PortableInfobox/tests/phpunit/XmlParserTest.php

45 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2018-08-08 09:42:22 +00:00
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\XmlParser
2018-08-08 09:42:22 +00:00
*/
class XmlParserTest extends MediaWikiTestCase {
/** @dataProvider contentTagsDataProvider */
public function testXHTMLParsing( $tag, $content ) {
$markup = "<data source=\"asdfd\"><{$tag}>{$content}</{$tag}></data>";
$result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
2015-05-20 10:15:22 +00:00
$this->assertEquals( $content, (string)$result->{$tag} );
}
2015-05-19 14:01:53 +00:00
public function contentTagsDataProvider() {
return [
[ 'default', 'sadf <br> sakdjfl' ],
[ 'format', '<>' ],
[ 'label', '' ]
];
2015-05-19 14:01:53 +00:00
}
/**
* @dataProvider entitiesTestDataProvider
*/
public function testHTMLEntities( $markup, $expectedResult ) {
$result = PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
2021-09-11 23:07:07 +00:00
$this->assertEquals( $expectedResult, $result[ 0 ] );
}
public function entitiesTestDataProvider() {
return [
[ '<data></data>', '' ],
[ '<data>&aksjdf;</data>', '&aksjdf;' ],
[ '<data>&amp;</data>', '&' ],
2015-07-07 07:06:37 +00:00
[ '<data>&middot;</data>', '·' ],
[ '<data>&Uuml;</data>', 'Ü' ],
[ '<data>&Delta;</data>', 'Δ' ],
[ '<data>&amp;amp;</data>', '&amp;' ],
[ '<data>&amp</data>', '&amp' ]
];
}
}