PortableInfobox/tests/phpunit/nodes/NodeTitleTest.php
2018-12-27 02:01:19 +01:00

82 lines
2 KiB
PHP

<?php
/**
* @group PortableInfobox
* @covers PortableInfobox\Parser\Nodes\NodeTitle
*/
class NodeTitleTest extends MediaWikiTestCase {
/**
* @covers PortableInfobox\Parser\Nodes\NodeTitle::getData
* @dataProvider dataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testData( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getData() );
}
public function dataProvider() {
return [
[
'<title source="test"/>',
[ 'test' => 'test' ],
[ 'value' => 'test', 'source' => 'test' ]
],
[
'<title source="test"><default>def</default></title>',
[],
[ 'value' => 'def', 'source' => 'test' ]
],
[
'<title source="test"><default>def</default></title>',
[],
[ 'value' => 'def', 'source' => 'test' ]
],
[
'<title source="test"><default>def</default></title>',
[ 'l' => 1 ],
[ 'value' => 'def', 'source' => 'test' ]
],
[
'<title source="test"><default>def</default></title>',
[ 'l' => 1 ],
[ 'value' => 'def', 'source' => 'test' ]
],
[
'<title source="test"><default>def</default></title>',
[ 'test' => 1 ],
[ 'value' => 1, 'source' => 'test' ]
],
[
'<title></title>',
[],
[ 'value' => null, 'source' => null ]
],
[
'<title source="test"><format>{{{test}}}%</format><default>def</default></title>',
[ 'test' => 1 ],
[ 'value' => '{{{test}}}%', 'source' => 'test' ]
],
[
'<title source="test"><format>{{{not_defined_var}}}%</format><default>def</default></title>',
[ 'test' => 1 ],
[ 'value' => '{{{not_defined_var}}}%', 'source' => 'test' ]
],
[
'<title source="test"><format>{{{test}}}%</format><default>def</default></title>',
[],
[ 'value' => 'def', 'source' => 'test' ]
],
[
'<title source="test"><format>{{{test}}}%</format></title>',
[ 'test' => 0 ],
[ 'value' => '{{{test}}}%', 'source' => 'test' ]
]
];
}
}