PortableInfobox/tests/phpunit/XmlParserTest.php

48 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2022-03-11 20:35:51 +00:00
use PortableInfobox\Parser\XmlParser;
2018-08-08 09:42:22 +00:00
/**
* @group PortableInfobox
2022-03-11 20:35:51 +00:00
* @covers \PortableInfobox\Parser\XmlParser
2018-08-08 09:42:22 +00:00
*/
2021-12-15 22:01:13 +00:00
class XmlParserTest extends MediaWikiIntegrationTestCase {
/** @dataProvider contentTagsDataProvider */
public function testXHTMLParsing( $tag, $content ) {
$markup = "<data source=\"asdfd\"><{$tag}>{$content}</{$tag}></data>";
2022-03-11 20:35:51 +00:00
$result = 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 ) {
2022-03-11 20:35:51 +00:00
$result = 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' ]
];
}
}