PortableInfobox/tests/nodes/NodeNavigationTest.php

71 lines
1.9 KiB
PHP
Raw Normal View History

2015-05-20 14:38:23 +00:00
<?php
2015-06-11 12:51:54 +00:00
class NodeNavigationTest extends WikiaBaseTest {
2015-05-20 14:38:23 +00:00
protected function setUp() {
2015-06-11 12:51:54 +00:00
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
2015-05-20 14:38:23 +00:00
parent::setUp();
}
2015-06-11 12:51:54 +00:00
/**
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeNavigation::getData
* @covers \Wikia\PortableInfobox\Parser\Nodes\Node::getInnerValue
2015-06-11 12:51:54 +00:00
* @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 [
[ '<navigation></navigation>', [ ], [ 'value' => '' ] ],
[ '<navigation>kjdflkja dafkjlsdkfj</navigation>', [ ], [ 'value' => 'kjdflkja dafkjlsdkfj' ] ],
[ '<navigation>kjdflkja<ref>dafkjlsdkfj</ref></navigation>', [ ], [ 'value' => 'kjdflkja<ref>dafkjlsdkfj</ref>' ] ],
2015-06-11 12:51:54 +00:00
];
}
2015-05-20 14:38:23 +00:00
/**
2017-03-15 18:07:51 +00:00
* @dataProvider isEmptyDataProvider
2015-05-20 14:38:23 +00:00
*/
public function testIsEmpty( $string, $expectedOutput ) {
$xml = simplexml_load_string( $string );
$node = new Wikia\PortableInfobox\Parser\Nodes\NodeNavigation( $xml, [ ] );
2015-05-20 14:38:23 +00:00
$data = $node->getData();
$this->assertTrue( $node->isEmpty( $data ) == $expectedOutput );
}
2015-06-11 12:51:54 +00:00
2017-03-15 18:07:51 +00:00
public function isEmptyDataProvider() {
2015-05-20 14:38:23 +00:00
return [
[
'string' => '<navigation>goodnight</navigation>',
2015-05-20 14:38:23 +00:00
'expectedOutput' => false
],
[
'string' => '<navigation>null</navigation>',
2015-05-20 14:38:23 +00:00
'expectedOutput' => false
],
[
'string' => '<navigation>0</navigation>',
2015-05-20 14:57:43 +00:00
'expectedOutput' => false
],
[
'string' => '<navigation>\'0\'</navigation>',
2015-05-20 14:57:43 +00:00
'expectedOutput' => false
2015-05-20 14:38:23 +00:00
],
[
'string' => '<navigation></navigation>',
2015-05-20 14:38:23 +00:00
'expectedOutput' => true
],
[
'string' => '<navigation> </navigation>',
2015-05-20 14:38:23 +00:00
'expectedOutput' => true
]
];
}
2017-03-15 18:07:51 +00:00
}