2018-08-13 14:31:50 +00:00
|
|
|
<?php
|
|
|
|
|
2022-03-11 20:35:51 +00:00
|
|
|
use PortableInfobox\Parser\Nodes\NodeData;
|
2018-08-13 14:31:50 +00:00
|
|
|
use PortableInfobox\Parser\Nodes\NodeFactory;
|
2022-03-11 20:35:51 +00:00
|
|
|
use PortableInfobox\Parser\Nodes\NodeImage;
|
|
|
|
use PortableInfobox\Parser\Nodes\NodeInfobox;
|
|
|
|
use PortableInfobox\Parser\Nodes\NodeMedia;
|
|
|
|
use PortableInfobox\Parser\Nodes\NodeUnimplemented;
|
|
|
|
use PortableInfobox\Parser\XmlMarkupParseErrorException;
|
|
|
|
use PortableInfobox\Parser\XmlParser;
|
2018-08-13 14:31:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group PortableInfobox
|
2022-03-11 20:35:51 +00:00
|
|
|
* @covers \PortableInfobox\Parser\Nodes\NodeFactory
|
2018-08-13 14:31:50 +00:00
|
|
|
*/
|
2021-12-15 22:01:13 +00:00
|
|
|
class NodeFactoryTest extends MediaWikiIntegrationTestCase {
|
2018-08-13 14:31:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider newFromXMLProvider
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
2022-03-11 20:35:51 +00:00
|
|
|
* @throws XmlMarkupParseErrorException
|
2018-08-13 14:31:50 +00:00
|
|
|
*/
|
|
|
|
public function testNewFromXML( $markup, $expected ) {
|
|
|
|
$node = NodeFactory::newFromXML( $markup, [] );
|
|
|
|
$this->assertEquals( $expected, get_class( $node ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider newFromXMLProvider
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
2022-03-11 20:35:51 +00:00
|
|
|
* @throws XmlMarkupParseErrorException
|
2018-08-13 14:31:50 +00:00
|
|
|
*/
|
|
|
|
public function testNewFromSimpleXml( $markup, $expected ) {
|
2022-03-11 20:35:51 +00:00
|
|
|
$xmlObj = XmlParser::parseXmlString( $markup );
|
2018-08-13 14:31:50 +00:00
|
|
|
$node = NodeFactory::newFromSimpleXml( $xmlObj, [] );
|
|
|
|
$this->assertEquals( $expected, get_class( $node ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newFromXMLProvider() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'<infobox />',
|
2022-03-11 20:35:51 +00:00
|
|
|
NodeInfobox::class
|
2018-08-13 14:31:50 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data />',
|
2022-03-11 20:35:51 +00:00
|
|
|
NodeData::class
|
2018-08-13 14:31:50 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<MEDIA />',
|
2022-03-11 20:35:51 +00:00
|
|
|
NodeMedia::class
|
2018-08-13 14:31:50 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<image><default></default><othertag></othertag></image>',
|
2022-03-11 20:35:51 +00:00
|
|
|
NodeImage::class
|
2018-08-13 14:31:50 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<idonotexist />',
|
2022-03-11 20:35:51 +00:00
|
|
|
NodeUnimplemented::class
|
2018-08-13 14:31:50 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2018-08-16 09:25:53 +00:00
|
|
|
}
|