PortableInfobox/tests/phpunit/nodes/NodeFactoryTest.php

59 lines
1.4 KiB
PHP
Raw Normal View History

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