PortableInfobox/tests/phpunit/nodes/NodeTitleTest.php

96 lines
2.6 KiB
PHP
Raw Normal View History

2018-08-13 14:31:50 +00:00
<?php
2022-03-11 20:35:51 +00:00
use PortableInfobox\Parser\Nodes\NodeFactory;
2018-08-13 14:31:50 +00:00
/**
* @group PortableInfobox
2022-03-11 20:35:51 +00:00
* @covers \PortableInfobox\Parser\Nodes\NodeTitle
* @coversDefaultClass \PortableInfobox\Parser\Nodes\NodeTitle
2018-08-13 14:31:50 +00:00
*/
2021-12-15 22:01:13 +00:00
class NodeTitleTest extends MediaWikiIntegrationTestCase {
2018-08-13 14:31:50 +00:00
/**
2022-03-11 20:35:51 +00:00
* @covers ::getData
2018-08-13 14:31:50 +00:00
* @dataProvider dataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testData( $markup, $params, $expected ) {
2022-03-11 20:35:51 +00:00
$node = NodeFactory::newFromXML( $markup, $params );
2018-08-13 14:31:50 +00:00
$this->assertEquals( $expected, $node->getData() );
}
public function dataProvider() {
return [
2018-10-02 07:41:19 +00:00
[
'<title source="test"/>',
[ 'test' => 'test' ],
2019-02-02 22:34:48 +00:00
[ 'value' => 'test', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><default>def</default></title>',
[],
2019-02-02 22:34:48 +00:00
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><default>def</default></title>',
[],
2019-02-02 22:34:48 +00:00
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><default>def</default></title>',
[ 'l' => 1 ],
2019-02-02 22:34:48 +00:00
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><default>def</default></title>',
[ 'l' => 1 ],
2019-02-02 22:34:48 +00:00
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><default>def</default></title>',
[ 'test' => 1 ],
2019-02-02 22:34:48 +00:00
[ 'value' => 1, 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title></title>',
[],
2019-02-02 22:34:48 +00:00
[ 'value' => null, 'source' => null, 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><format>{{{test}}}%</format><default>def</default></title>',
[ 'test' => 1 ],
2019-02-02 22:34:48 +00:00
[ 'value' => '{{{test}}}%', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><format>{{{not_defined_var}}}%</format><default>def</default></title>',
[ 'test' => 1 ],
2019-02-02 22:34:48 +00:00
[ 'value' => '{{{not_defined_var}}}%', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><format>{{{test}}}%</format><default>def</default></title>',
[],
2019-02-02 22:34:48 +00:00
[ 'value' => 'def', 'source' => 'test', 'item-name' => null ]
2018-10-02 07:41:19 +00:00
],
[
'<title source="test"><format>{{{test}}}%</format></title>',
[ 'test' => 0 ],
2019-02-02 22:34:48 +00:00
[ 'value' => '{{{test}}}%', 'source' => 'test', 'item-name' => null ]
2019-02-03 16:49:06 +00:00
],
[
'<title source="test" name="nametest" />',
[ 'test' => 'abc' ],
[ 'value' => 'abc', 'source' => 'test', 'item-name' => 'nametest' ]
],
[
'<title name="nametest"><default>def</default></title>',
[],
[ 'value' => 'def', 'source' => null, 'item-name' => 'nametest' ]
2018-10-02 07:41:19 +00:00
]
2018-08-13 14:31:50 +00:00
];
}
}