setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
parent::setUp();
}
/**
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getSource
* @dataProvider sourceDataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testSource( $markup, $params, $expected ) {
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getSource() );
}
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 \Wikia\PortableInfobox\Parser\Nodes\Node::getSourceLabel
* @dataProvider sourceLabelDataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testSourceLabel( $markup, $params, $expected ) {
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getSourceLabel() );
}
public function sourceLabelDataProvider() {
return [
[ '', [ ], ['test' => ''] ],
[ '', [ ], ['test' => ''] ],
[ '
', [ ], ['test' => ''] ],
[ '{{{test}}}',
[ ], ['test' => ''] ],
[ '{{{test}}}',
[ ], ['test' => '{{{test}}}'] ],
[ '', [ ], ['test' => 'testLabel'] ],
[ '', [ ], [ ] ],
[ '', [], ['test' =>'labelInsideGroup'] ],
[ '' .
'' .
'' .
'',
[], ['test' =>'labelInsideGroup', 'test2' =>'labelInsideGroup2'] ],
[ '' .
'' .
'' .
'' .
'' .
'',
[], ['test' =>'labelInsideGroup', 'test2' =>'labelInsideGroup2', 'title' => '', 'image' => ''] ],
[ '{{{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' => '' ] ],
[ '' .
'' .
'{{#if: {{{test2|}}}| [[{{{test2}}} with some text]] }}' .
'',
[ ], [ 'test1' => 'label (test1)', 'test2' => 'label (test2)' ] ],
[ '' .
'' .
'{{#switch: {{{test2|}}}|{{{test3}}}|{{{test4|kdjk|sajdkfj|}}}]] }}' .
'',
[ ], [ 'test2' => 'other label (test2)', 'test3' => 'other label (test3)', 'test4' => 'other label (test4)' ] ],
[ '' .
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[ 'test1' => 'blabla' ],
[
'test1' => 'next label (test1)',
'test2' => 'next label (test2)',
'test3' => 'next label (test3)',
'test4' => 'next label (test4)',
'test5' => 'next label (test5)'
]
],
[ '' .
'' .
'my {{{test2}}}$$$' .
'{{#switch: {{{test3|}}}|{{{test4}}}|{{{test5|kdjk|sajdkfj|}}}]] }}' .
'',
[ ],
[
'test2' => 'last label (test2)',
'test3' => 'last label (test3)',
'test4' => 'last label (test4)',
'test5' => 'last label (test5)'
]
]
];
}
/**
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getExternalParser
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::setExternalParser
* @dataProvider parserTestDataProvider
*
* @param $parser
* @param $expected
*/
public function testExternalParserSetUp( $parser, $expected ) {
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( '', [ ] );
$this->assertEquals( $expected, $node->setExternalParser( $parser )->getExternalParser() );
}
public function parserTestDataProvider() {
return [
[ null, new \Wikia\PortableInfobox\Parser\SimpleParser() ],
[ new \Wikia\PortableInfobox\Parser\SimpleParser(), new \Wikia\PortableInfobox\Parser\SimpleParser() ]
];
}
/**
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeData::getData
* @dataProvider dataProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testData( $markup, $params, $expected ) {
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getData() );
}
public function dataProvider() {
return [
[ '', [ 'test' => 'test' ], [ 'value' => 'test', 'label' => '' ] ],
[ 'def', [ ], [ 'value' => 'def', 'label' => '' ] ],
[ 'def', [ ],
[ 'value' => 'def', 'label' => 'l' ] ],
[ 'def', [ 'l' => 1 ],
[ 'value' => 'def', 'label' => 'jjj' ] ],
[ 'def', [ 'l' => 1 ],
[ 'value' => 'def', 'label' => '' ] ],
[ 'def', [ 'test' => 1 ],
[ 'value' => 1, 'label' => 'l' ] ],
[ '', [ ], [ 'label' => '', 'value' => null ] ],
[ '{{{test}}}%def', [ 'test' => 1 ],
[ 'value' => '{{{test}}}%', 'label' => 'l' ] ],
[ '{{{not_defined_var}}}%def', [ 'test' => 1 ],
[ 'value' => '{{{not_defined_var}}}%', 'label' => 'l' ] ],
[ '{{{test}}}%def', [ ],
[ 'value' => 'def', 'label' => 'l' ] ],
[ '{{{test}}}%', [ 'test' => 0 ],
[ 'value' => '{{{test}}}%', 'label' => '' ] ],
];
}
/**
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getRenderData
* @dataProvider dataRenderProvider
*
* @param $markup
* @param $params
* @param $expected
*/
public function testRenderData( $markup, $params, $expected ) {
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
$this->assertEquals( $expected, $node->getRenderData() );
}
public function dataRenderProvider() {
return [
[ '',
[ 'test' => 'test' ],
[ 'type' => 'data', 'data' => [ 'value' => 'test', 'label' => '' ] ]
]
];
}
/**
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::isType
* @dataProvider isTypeDataProvider
*
* @param $markup
* @param $typeToCheck
* @param $expected
*/
public function testIsType( $markup, $typeToCheck, $expected ) {
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] );
$this->assertEquals( $expected, $node->isType( $typeToCheck ) );
}
public function isTypeDataProvider() {
return [
[ '', 'data', true ],
[ '', 'DaTa', true ],
[ '', 'aksdjflkj', false ],
];
}
/**
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getType
* @dataProvider typeDataProvider
*
* @param $markup
* @param $expected
*/
public function testType( $markup, $expected ) {
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] );
$this->assertEquals( $expected, $node->getType() );
}
public function typeDataProvider() {
return [
[ '', 'data' ],
[ '', 'infobox' ],
];
}
/**
* @dataProvider testIsEmptyDataProvider
*/
public function testIsEmpty( $season, $expectedOutput ) {
$string = '';
$xml = simplexml_load_string( $string );
$node = new Wikia\PortableInfobox\Parser\Nodes\NodeData( $xml, [ 'season' => $season ] );
$nodeData = $node->getData();
$this->assertTrue( $node->isEmpty( $nodeData ) == $expectedOutput );
}
public function testIsEmptyDataProvider() {
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
]
];
}
}