2015-06-11 12:51:54 +00:00
|
|
|
<?php
|
2018-08-08 09:42:22 +00:00
|
|
|
/**
|
|
|
|
* @group PortableInfobox
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node
|
2018-08-08 09:42:22 +00:00
|
|
|
*/
|
|
|
|
class NodeDataTest extends MediaWikiTestCase {
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::getSources
|
2015-06-11 12:51:54 +00:00
|
|
|
* @dataProvider sourceDataProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testSource( $markup, $params, $expected ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
2016-12-14 12:54:53 +00:00
|
|
|
$this->assertEquals( $expected, $node->getSources() );
|
2015-06-11 12:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function sourceDataProvider() {
|
|
|
|
return [
|
2018-08-16 09:25:53 +00:00
|
|
|
[ '<data source="test"></data>', [], [ 'test' ] ],
|
2015-06-12 13:43:37 +00:00
|
|
|
[ '<data source="test"><label source="test">{{{test}}}</label><default>{{{test}}}</default></data>',
|
2018-08-16 09:25:53 +00:00
|
|
|
[], [ 'test' ] ],
|
|
|
|
[ '<data source="test"><default>{{{test 2}}}</default></data>', [], [ 'test', 'test 2' ] ],
|
|
|
|
[ '<data></data>', [], [] ],
|
2015-06-16 08:52:18 +00:00
|
|
|
[ '<data source="test1"><default>{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}</default></data>',
|
2018-08-16 09:25:53 +00:00
|
|
|
[], [ 'test1', 'test2' ] ],
|
2015-06-16 08:52:18 +00:00
|
|
|
[ '<data><default>{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}</default></data>',
|
2018-08-16 09:25:53 +00:00
|
|
|
[], [ 'test2', 'test3', 'test4' ] ],
|
2015-06-23 11:05:25 +00:00
|
|
|
[ '<data source="test1"><format>my {{{test2}}}$$$</format><default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default></data>',
|
|
|
|
[ 'test1' => 'blabla' ], [ 'test1', 'test2', 'test3', 'test4', 'test5' ] ],
|
|
|
|
[ '<data><format>my {{{test2}}}$$$</format><default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default></data>',
|
2018-08-16 09:25:53 +00:00
|
|
|
[], [ 'test2', 'test3', 'test4', 'test5' ] ]
|
2015-06-11 12:51:54 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-03-31 10:00:03 +00:00
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::getSourcesMetadata
|
2016-12-14 14:46:17 +00:00
|
|
|
* @dataProvider sourcesMetadataDataProvider
|
2016-03-31 10:00:03 +00:00
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
2016-12-14 14:46:17 +00:00
|
|
|
public function testSourcesMetadata( $markup, $params, $expected ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
2016-03-31 10:00:03 +00:00
|
|
|
|
2016-12-14 14:46:17 +00:00
|
|
|
$this->assertEquals( $expected, $node->getSourcesMetadata() );
|
2016-03-31 10:00:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 14:46:17 +00:00
|
|
|
public function sourcesMetadataDataProvider() {
|
2016-03-31 10:00:03 +00:00
|
|
|
return [
|
2016-12-14 14:46:17 +00:00
|
|
|
[
|
|
|
|
'<data source="test"></data>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<image source="test"/>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<title source="test"/>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data source="test"><default>{{{test}}}</default></data>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data source="test"><label source="test">{{{test}}}</label><default>{{{test}}}</default></data>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test' => [
|
|
|
|
'label' => '{{{test}}}',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data source="test"><label>testLabel</label></data>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test' => [
|
|
|
|
'label' => 'testLabel',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[ '<data></data>', [], [] ],
|
|
|
|
[
|
|
|
|
'<data source="test"><default>{{{test 2}}}</default></data>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
],
|
|
|
|
'test 2' => [
|
|
|
|
'label' => ''
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data source="test1"><default>{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}</default></data>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test1' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
],
|
|
|
|
'test2' => [
|
|
|
|
'label' => ''
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data><default>{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}</default></data>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test2' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test3' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test4' => [
|
|
|
|
'label' => ''
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data source="test1">' .
|
2016-04-01 12:54:43 +00:00
|
|
|
'<format>my {{{test2}}}$$$</format>' .
|
|
|
|
'<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' .
|
|
|
|
'</data>',
|
2016-12-14 14:46:17 +00:00
|
|
|
[ 'test1' => 'blabla' ],
|
|
|
|
[
|
|
|
|
'test1' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
],
|
|
|
|
'test2' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test3' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test4' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test5' => [
|
|
|
|
'label' => ''
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data>' .
|
2016-04-01 12:54:43 +00:00
|
|
|
'<format>my {{{test2}}}$$$</format>' .
|
|
|
|
'<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' .
|
|
|
|
'</data>',
|
2016-12-14 14:46:17 +00:00
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test2' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test3' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test4' => [
|
|
|
|
'label' => ''
|
|
|
|
],
|
|
|
|
'test5' => [
|
|
|
|
'label' => ''
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data source="test1">' .
|
2016-04-01 12:54:43 +00:00
|
|
|
'<label>label</label>' .
|
|
|
|
'<default>{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}</default>' .
|
|
|
|
'</data>',
|
2016-12-14 14:46:17 +00:00
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test1' => [
|
|
|
|
'label' => 'label (test1)',
|
|
|
|
'primary' => true
|
|
|
|
],
|
|
|
|
'test2' => [
|
|
|
|
'label' => 'label (test2)'
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data>' .
|
2016-04-01 12:54:43 +00:00
|
|
|
'<label>other label</label>' .
|
|
|
|
'<default>{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}</default>' .
|
|
|
|
'</data>',
|
2016-12-14 14:46:17 +00:00
|
|
|
[],
|
|
|
|
[
|
|
|
|
'test2' => [
|
|
|
|
'label' => 'other label (test2)'
|
|
|
|
],
|
|
|
|
'test3' => [
|
|
|
|
'label' => 'other label (test3)'
|
|
|
|
],
|
|
|
|
'test4' => [
|
|
|
|
'label' => 'other label (test4)'
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<data source="test1">' .
|
2016-04-01 12:54:43 +00:00
|
|
|
'<label>next label</label>' .
|
|
|
|
'<format>my {{{test2}}}$$$</format>' .
|
|
|
|
'<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' .
|
|
|
|
'</data>',
|
|
|
|
[ 'test1' => 'blabla' ],
|
|
|
|
[
|
2016-12-14 14:46:17 +00:00
|
|
|
'test1' => [
|
|
|
|
'label' => 'next label (test1)',
|
|
|
|
'primary' => true
|
|
|
|
],
|
|
|
|
'test2' => [
|
|
|
|
'label' => 'next label (test2)'
|
|
|
|
],
|
|
|
|
'test3' => [
|
|
|
|
'label' => 'next label (test3)'
|
|
|
|
],
|
|
|
|
'test4' => [
|
|
|
|
'label' => 'next label (test4)'
|
|
|
|
],
|
|
|
|
'test5' => [
|
|
|
|
'label' => 'next label (test5)'
|
|
|
|
]
|
2016-04-01 12:54:43 +00:00
|
|
|
]
|
|
|
|
],
|
2016-12-14 14:46:17 +00:00
|
|
|
[
|
|
|
|
'<data>' .
|
2016-04-01 12:54:43 +00:00
|
|
|
'<label>last label</label>' .
|
|
|
|
'<format>my {{{test2}}}$$$</format>' .
|
|
|
|
'<default>{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}</default>' .
|
|
|
|
'</data>',
|
2016-12-14 14:46:17 +00:00
|
|
|
[],
|
2016-04-01 12:54:43 +00:00
|
|
|
[
|
2016-12-14 14:46:17 +00:00
|
|
|
'test2' => [
|
|
|
|
'label' => 'last label (test2)'
|
|
|
|
],
|
|
|
|
'test3' => [
|
|
|
|
'label' => 'last label (test3)'
|
|
|
|
],
|
|
|
|
'test4' => [
|
|
|
|
'label' => 'last label (test4)'
|
|
|
|
],
|
|
|
|
'test5' => [
|
|
|
|
'label' => 'last label (test5)'
|
|
|
|
]
|
2016-04-01 12:54:43 +00:00
|
|
|
]
|
|
|
|
]
|
2016-03-31 10:00:03 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-12-14 16:32:10 +00:00
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::getMetadata
|
2018-08-13 14:31:50 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeInfobox::getMetadata
|
2016-12-14 16:32:10 +00:00
|
|
|
* @dataProvider metadataDataProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testMetadata( $markup, $params, $expected ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
2016-12-14 16:32:10 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getMetadata() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function metadataDataProvider() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'<infobox><data source="test"></data></infobox>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'sources' => [
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<infobox><image source="test"/></infobox>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
[
|
2018-08-26 14:08:31 +00:00
|
|
|
'type' => 'media',
|
2016-12-14 16:32:10 +00:00
|
|
|
'sources' => [
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<infobox><title source="test"/></infobox>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'type' => 'title',
|
|
|
|
'sources' => [
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<infobox><data source="test"><default>{{{test}}}</default></data></infobox>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'sources' => [
|
|
|
|
'test' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<infobox><group>' .
|
|
|
|
'<image source="test1" />' .
|
|
|
|
'<title source="test2" />' .
|
|
|
|
'</group></infobox>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'type' => 'group',
|
|
|
|
'metadata' => [
|
|
|
|
[
|
2018-08-26 14:08:31 +00:00
|
|
|
'type' => 'media',
|
2016-12-14 16:32:10 +00:00
|
|
|
'sources' => [
|
|
|
|
'test1' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'title',
|
|
|
|
'sources' => [
|
|
|
|
'test2' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<infobox><group>' .
|
|
|
|
'<data source="test1"><label>Label</label></data>' .
|
|
|
|
'<group>' .
|
|
|
|
'<image source="test2" />' .
|
|
|
|
'<title source="test3" />' .
|
|
|
|
'</group>' .
|
|
|
|
'</group></infobox>',
|
|
|
|
[],
|
2016-04-01 12:54:43 +00:00
|
|
|
[
|
2016-12-14 16:32:10 +00:00
|
|
|
[
|
|
|
|
'type' => 'group',
|
|
|
|
'metadata' => [
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'sources' => [
|
|
|
|
'test1' => [
|
|
|
|
'label' => 'Label',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'group',
|
|
|
|
'metadata' => [
|
|
|
|
[
|
2018-08-26 14:08:31 +00:00
|
|
|
'type' => 'media',
|
2016-12-14 16:32:10 +00:00
|
|
|
'sources' => [
|
|
|
|
'test2' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'title',
|
|
|
|
'sources' => [
|
|
|
|
'test3' => [
|
|
|
|
'label' => '',
|
|
|
|
'primary' => true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2016-04-01 12:54:43 +00:00
|
|
|
]
|
|
|
|
]
|
2016-03-31 10:00:03 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:51:54 +00:00
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::getExternalParser
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::setExternalParser
|
2015-06-11 12:51:54 +00:00
|
|
|
* @dataProvider parserTestDataProvider
|
|
|
|
*
|
|
|
|
* @param $parser
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testExternalParserSetUp( $parser, $expected ) {
|
2018-08-16 09:25:53 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( '<data></data>', [] );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->setExternalParser( $parser )->getExternalParser() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function parserTestDataProvider() {
|
|
|
|
return [
|
2018-08-09 09:49:10 +00:00
|
|
|
[ null, new PortableInfobox\Parser\SimpleParser() ],
|
|
|
|
[ new PortableInfobox\Parser\SimpleParser(), new PortableInfobox\Parser\SimpleParser() ]
|
2015-06-11 12:51:54 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeData::getData
|
2015-06-11 12:51:54 +00:00
|
|
|
* @dataProvider dataProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testData( $markup, $params, $expected ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getData() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataProvider() {
|
|
|
|
return [
|
2017-01-10 12:59:46 +00:00
|
|
|
[ '<data source="test"></data>', [ 'test' => 'test' ], [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ],
|
|
|
|
[ '<data source="test" span="2"></data>', [ 'test' => 'test' ], [ 'value' => 'test', 'label' => '', 'span' => '2', 'layout' => null ] ],
|
|
|
|
[ '<data source="test" span="2.2"></data>', [ 'test' => 'test' ], [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ],
|
|
|
|
[ '<data source="test" span="non_numeric_span"></data>', [ 'test' => 'test' ], [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ],
|
|
|
|
[ '<data source="test" layout="wrong layout"></data>', [ 'test' => 'test' ], [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ],
|
|
|
|
[ '<data source="test" layout="default"></data>', [ 'test' => 'test' ], [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => 'default' ] ],
|
2018-08-16 09:25:53 +00:00
|
|
|
[ '<data source="test"><default>def</default></data>', [], [ 'value' => 'def', 'label' => '', 'span' => 1, 'layout' => null ] ],
|
|
|
|
[ '<data source="test"><label>l</label><default>def</default></data>', [],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => 'def', 'label' => 'l', 'span' => 1, 'layout' => null ] ],
|
2015-07-01 08:55:58 +00:00
|
|
|
[ '<data source="test"><label source="l">jjj</label><default>def</default></data>', [ 'l' => 1 ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => 'def', 'label' => 'jjj', 'span' => 1, 'layout' => null ] ],
|
2015-07-01 08:55:58 +00:00
|
|
|
[ '<data source="test"><label source="l" /><default>def</default></data>', [ 'l' => 1 ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => 'def', 'label' => '', 'span' => 1, 'layout' => null ] ],
|
2015-06-11 12:51:54 +00:00
|
|
|
[ '<data source="test"><label>l</label><default>def</default></data>', [ 'test' => 1 ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => 1, 'label' => 'l', 'span' => 1, 'layout' => null ] ],
|
2018-08-16 09:25:53 +00:00
|
|
|
[ '<data></data>', [], [ 'label' => '', 'value' => null, 'span' => 1, 'layout' => null ] ],
|
2015-06-22 15:38:47 +00:00
|
|
|
[ '<data source="test"><label>l</label><format>{{{test}}}%</format><default>def</default></data>', [ 'test' => 1 ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => '{{{test}}}%', 'label' => 'l', 'span' => 1, 'layout' => null ] ],
|
2015-06-22 15:38:47 +00:00
|
|
|
[ '<data source="test"><label>l</label><format>{{{not_defined_var}}}%</format><default>def</default></data>', [ 'test' => 1 ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => '{{{not_defined_var}}}%', 'label' => 'l', 'span' => 1, 'layout' => null ] ],
|
2018-08-16 09:25:53 +00:00
|
|
|
[ '<data source="test"><label>l</label><format>{{{test}}}%</format><default>def</default></data>', [],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => 'def', 'label' => 'l', 'span' => 1, 'layout' => null ] ],
|
2015-09-08 09:29:49 +00:00
|
|
|
[ '<data source="test"><format>{{{test}}}%</format></data>', [ 'test' => 0 ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'value' => '{{{test}}}%', 'label' => '', 'span' => 1, 'layout' => null ] ],
|
2015-06-11 12:51:54 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::getRenderData
|
2018-08-13 14:31:50 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeData::getLayout
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeData::getSpan
|
2015-06-11 12:51:54 +00:00
|
|
|
* @dataProvider dataRenderProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testRenderData( $markup, $params, $expected ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getRenderData() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataRenderProvider() {
|
|
|
|
return [
|
2015-06-22 15:38:47 +00:00
|
|
|
[ '<data source="test"></data>',
|
|
|
|
[ 'test' => 'test' ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ]
|
|
|
|
],
|
|
|
|
[ '<data source="test" layout="default"></data>',
|
|
|
|
[ 'test' => 'test' ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => 'default' ] ]
|
|
|
|
],
|
|
|
|
[ '<data source="test" layout="wrong_layout"></data>',
|
|
|
|
[ 'test' => 'test' ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ]
|
|
|
|
],
|
|
|
|
[ '<data source="test" span="2"></data>',
|
|
|
|
[ 'test' => 'test' ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'test', 'label' => '', 'span' => '2', 'layout' => null ] ]
|
|
|
|
],
|
|
|
|
[ '<data source="test" span="2.2"></data>',
|
|
|
|
[ 'test' => 'test' ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ]
|
|
|
|
],
|
|
|
|
[ '<data source="test" span="non numeric span"></data>',
|
|
|
|
[ 'test' => 'test' ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'test', 'label' => '', 'span' => 1, 'layout' => null ] ]
|
|
|
|
],
|
2015-06-11 12:51:54 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::isType
|
2015-06-11 12:51:54 +00:00
|
|
|
* @dataProvider isTypeDataProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $typeToCheck
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testIsType( $markup, $typeToCheck, $expected ) {
|
2018-08-16 09:25:53 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->isType( $typeToCheck ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isTypeDataProvider() {
|
|
|
|
return [
|
|
|
|
[ '<data source="test"></data>', 'data', true ],
|
|
|
|
[ '<data source="test"></data>', 'DaTa', true ],
|
|
|
|
[ '<data source="test"></data>', 'aksdjflkj', false ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\Node::getType
|
2015-06-11 12:51:54 +00:00
|
|
|
* @dataProvider typeDataProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testType( $markup, $expected ) {
|
2018-08-16 09:25:53 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getType() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function typeDataProvider() {
|
|
|
|
return [
|
|
|
|
[ '<data source="test"></data>', 'data' ],
|
|
|
|
[ '<infobox></infobox>', 'infobox' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-15 18:07:51 +00:00
|
|
|
* @dataProvider isEmptyDataProvider
|
2015-06-11 12:51:54 +00:00
|
|
|
*/
|
|
|
|
public function testIsEmpty( $season, $expectedOutput ) {
|
|
|
|
$string = '<data source="season"><label>Season</label></data>';
|
|
|
|
$xml = simplexml_load_string( $string );
|
|
|
|
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = new PortableInfobox\Parser\Nodes\NodeData( $xml, [ 'season' => $season ] );
|
2015-06-11 12:51:54 +00:00
|
|
|
$nodeData = $node->getData();
|
|
|
|
$this->assertTrue( $node->isEmpty( $nodeData ) == $expectedOutput );
|
|
|
|
}
|
|
|
|
|
2017-03-15 18:07:51 +00:00
|
|
|
public function isEmptyDataProvider() {
|
2015-06-11 12:51:54 +00:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'season' => '0',
|
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => '1',
|
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => 'one',
|
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => 'null',
|
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => 'false',
|
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => ' ',
|
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => null,
|
|
|
|
'expectedOutput' => true
|
|
|
|
],
|
|
|
|
[
|
2018-08-16 09:25:53 +00:00
|
|
|
'season' => [],
|
2015-06-11 12:51:54 +00:00
|
|
|
'expectedOutput' => true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => '',
|
|
|
|
'expectedOutput' => true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => 5,
|
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'season' => 0,
|
|
|
|
'expectedOutput' => false
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|