assertEquals( $expected, $node->getSources() );
}
public function sourceDataProvider() {
return [
[
'',
[],
[ 'test' ]
],
[
'' .
'{{{test}}}' .
'',
[],
[ 'test' ]
],
[
'{{{test 2}}}',
[],
[ 'test', 'test 2' ]
],
[
'',
[],
[]
],
[
'' .
'{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}' .
'',
[],
[ 'test1', 'test2' ]
],
[
'' .
'{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}' .
'',
[],
[ 'test2', 'test3', 'test4' ]
],
[
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[ 'test1' => 'blabla' ],
[ 'test1', 'test2', 'test3', 'test4', 'test5' ]
],
[
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[],
[ 'test2', 'test3', 'test4', 'test5' ]
]
];
}
/**
* @covers PortableInfobox\Parser\Nodes\Node::getSourcesMetadata
* @dataProvider sourcesMetadataDataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testSourcesMetadata( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getSourcesMetadata() );
}
public function sourcesMetadataDataProvider() {
return [
[
'',
[],
[
'test' => [
'label' => '',
'primary' => true
]
]
],
[
'',
[],
[
'test' => [
'label' => '',
'primary' => true
]
]
],
[
'
',
[],
[
'test' => [
'label' => '',
'primary' => true
]
]
],
[
'{{{test}}}',
[],
[
'test' => [
'label' => '',
'primary' => true
]
]
],
[
'' .
'{{{test}}}' .
'',
[],
[
'test' => [
'label' => '{{{test}}}',
'primary' => true
]
]
],
[
'',
[],
[
'test' => [
'label' => 'testLabel',
'primary' => true
]
]
],
[ '', [], [] ],
[
'{{{test 2}}}',
[],
[
'test' => [
'label' => '',
'primary' => true
],
'test 2' => [
'label' => ''
]
]
],
[
'' .
'{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}' .
'',
[],
[
'test1' => [
'label' => '',
'primary' => true
],
'test2' => [
'label' => ''
]
]
],
[
'' .
'{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}' .
'',
[],
[
'test2' => [
'label' => ''
],
'test3' => [
'label' => ''
],
'test4' => [
'label' => ''
]
]
],
[
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[ 'test1' => 'blabla' ],
[
'test1' => [
'label' => '',
'primary' => true
],
'test2' => [
'label' => ''
],
'test3' => [
'label' => ''
],
'test4' => [
'label' => ''
],
'test5' => [
'label' => ''
]
]
],
[
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[],
[
'test2' => [
'label' => ''
],
'test3' => [
'label' => ''
],
'test4' => [
'label' => ''
],
'test5' => [
'label' => ''
]
]
],
[
'' .
'' .
'{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}' .
'',
[],
[
'test1' => [
'label' => 'label (test1)',
'primary' => true
],
'test2' => [
'label' => 'label (test2)'
],
]
],
[
'' .
'' .
'{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}' .
'',
[],
[
'test2' => [
'label' => 'other label (test2)'
],
'test3' => [
'label' => 'other label (test3)'
],
'test4' => [
'label' => 'other label (test4)'
],
]
],
[
'' .
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[ 'test1' => 'blabla' ],
[
'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)'
]
]
],
[
'' .
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[],
[
'test2' => [
'label' => 'last label (test2)'
],
'test3' => [
'label' => 'last label (test3)'
],
'test4' => [
'label' => 'last label (test4)'
],
'test5' => [
'label' => 'last label (test5)'
]
]
]
];
}
/**
* @covers PortableInfobox\Parser\Nodes\Node::getMetadata
* @covers PortableInfobox\Parser\Nodes\NodeInfobox::getMetadata
* @dataProvider metadataDataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testMetadata( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getMetadata() );
}
public function metadataDataProvider() {
return [
[
'',
[],
[
[
'type' => 'data',
'sources' => [
'test' => [
'label' => '',
'primary' => true
]
]
]
]
],
[
'',
[],
[
[
'type' => 'media',
'sources' => [
'test' => [
'label' => '',
'primary' => true
]
]
]
]
],
[
'',
[],
[
[
'type' => 'title',
'sources' => [
'test' => [
'label' => '',
'primary' => true
]
]
]
]
],
[
'{{{test}}}',
[],
[
[
'type' => 'data',
'sources' => [
'test' => [
'label' => '',
'primary' => true
]
]
]
]
],
[
'' .
'' .
'' .
'',
[],
[
[
'type' => 'group',
'metadata' => [
[
'type' => 'media',
'sources' => [
'test1' => [
'label' => '',
'primary' => true
]
]
],
[
'type' => 'title',
'sources' => [
'test2' => [
'label' => '',
'primary' => true
]
]
]
]
]
]
],
[
'' .
'' .
'' .
'' .
'' .
'' .
'',
[],
[
[
'type' => 'group',
'metadata' => [
[
'type' => 'data',
'sources' => [
'test1' => [
'label' => 'Label',
'primary' => true
]
]
],
[
'type' => 'group',
'metadata' => [
[
'type' => 'media',
'sources' => [
'test2' => [
'label' => '',
'primary' => true
]
]
],
[
'type' => 'title',
'sources' => [
'test3' => [
'label' => '',
'primary' => true
]
]
]
]
]
]
]
]
]
];
}
/**
* @covers PortableInfobox\Parser\Nodes\Node::getExternalParser
* @covers PortableInfobox\Parser\Nodes\Node::setExternalParser
* @dataProvider parserTestDataProvider
*
* @param $parser
* @param $expected
*/
public function testExternalParserSetUp( $parser, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( '', [] );
$this->assertEquals( $expected, $node->setExternalParser( $parser )->getExternalParser() );
}
public function parserTestDataProvider() {
return [
[ null, new PortableInfobox\Parser\SimpleParser() ],
[ new PortableInfobox\Parser\SimpleParser(), new PortableInfobox\Parser\SimpleParser() ]
];
}
/**
* @covers PortableInfobox\Parser\Nodes\NodeData::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 [
[
'',
[ 'test' => 'test' ],
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'',
[ 'test' => 'test' ],
[
'value' => 'test',
'label' => '',
'span' => '2',
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'',
[ 'test' => 'test' ],
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'',
[ 'test' => 'test' ],
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'',
[ 'test' => 'test' ],
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'',
[ 'test' => 'test' ],
[
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => 'default',
'source' => 'test',
'item-name' => null
]
],
[
'def',
[],
[
'value' => 'def',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'def',
[],
[
'value' => 'def',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'def',
[ 'l' => 1 ],
[
'value' => 'def',
'label' => 'jjj',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'def',
[ 'l' => 1 ],
[
'value' => 'def',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'def',
[ 'test' => 1 ],
[
'value' => 1,
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'',
[],
[
'label' => '',
'value' => null,
'span' => 1,
'layout' => null,
'source' => null,
'item-name' => null
]
],
[
'{{{test}}}%def',
[ 'test' => 1 ],
[
'value' => '{{{test}}}%',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'' .
'{{{not_defined_var}}}%def' .
'',
[ 'test' => 1 ],
[
'value' => '{{{not_defined_var}}}%',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'{{{test}}}%def',
[],
[
'value' => 'def',
'label' => 'l',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
[
'{{{test}}}%',
[ 'test' => 0 ],
[
'value' => '{{{test}}}%',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
],
];
}
/**
* @covers PortableInfobox\Parser\Nodes\Node::getRenderData
* @covers PortableInfobox\Parser\Nodes\NodeData::getLayout
* @covers PortableInfobox\Parser\Nodes\NodeData::getSpan
* @dataProvider dataRenderProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testRenderData( $markup, $params, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getRenderData() );
}
public function dataRenderProvider() {
return [
[
'',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
'',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => 'default',
'source' => 'test',
'item-name' => null
]
]
],
[
'',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
'',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => '2',
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
'',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
'',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => null
]
]
],
[
'',
[ 'test' => 'test' ],
[
'type' => 'data',
'data' => [
'value' => 'test',
'label' => '',
'span' => 1,
'layout' => null,
'source' => 'test',
'item-name' => 'data name'
]
]
]
];
}
/**
* @covers PortableInfobox\Parser\Nodes\Node::isType
* @dataProvider isTypeDataProvider
*
* @param $markup
* @param $typeToCheck
* @param $expected
*/
public function testIsType( $markup, $typeToCheck, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, $node->isType( $typeToCheck ) );
}
public function isTypeDataProvider() {
return [
[ '', 'data', true ],
[ '', 'DaTa', true ],
[ '', 'aksdjflkj', false ],
];
}
/**
* @covers PortableInfobox\Parser\Nodes\Node::getType
* @dataProvider typeDataProvider
*
* @param $markup
* @param $expected
*/
public function testType( $markup, $expected ) {
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
$this->assertEquals( $expected, $node->getType() );
}
public function typeDataProvider() {
return [
[ '', 'data' ],
[ '', 'infobox' ],
];
}
/**
* @dataProvider isEmptyDataProvider
*/
public function testIsEmpty( $season, $expectedOutput ) {
$string = '';
$xml = simplexml_load_string( $string );
$node = new PortableInfobox\Parser\Nodes\NodeData( $xml, [ 'season' => $season ] );
$nodeData = $node->getData();
$this->assertTrue( $node->isEmpty( $nodeData ) == $expectedOutput );
}
public function isEmptyDataProvider() {
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
],
[
'season' => [],
'expectedOutput' => true
],
[
'season' => '',
'expectedOutput' => true
],
[
'season' => 5,
'expectedOutput' => false
],
[
'season' => 0,
'expectedOutput' => false
]
];
}
}