2015-05-20 14:38:23 +00:00
|
|
|
<?php
|
2022-03-11 20:35:51 +00:00
|
|
|
|
|
|
|
use PortableInfobox\Parser\Nodes\NodeFactory;
|
|
|
|
use PortableInfobox\Parser\Nodes\NodeNavigation;
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
/**
|
|
|
|
* @group PortableInfobox
|
2022-03-11 20:35:51 +00:00
|
|
|
* @covers \PortableInfobox\Parser\Nodes\NodeNavigation
|
2018-08-08 09:42:22 +00:00
|
|
|
*/
|
2021-12-15 22:01:13 +00:00
|
|
|
class NodeNavigationTest extends MediaWikiIntegrationTestCase {
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
/**
|
2022-03-11 20:35:51 +00:00
|
|
|
* @covers \PortableInfobox\Parser\Nodes\NodeNavigation::getData
|
|
|
|
* @covers \PortableInfobox\Parser\Nodes\Node::getInnerValue
|
2015-06-11 12:51:54 +00:00
|
|
|
* @dataProvider dataProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
|
|
|
*/
|
2018-10-02 07:41:19 +00:00
|
|
|
public function testData( $markup, $expected ) {
|
2022-03-11 20:35:51 +00:00
|
|
|
$node = NodeFactory::newFromXML( $markup );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getData() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataProvider() {
|
|
|
|
return [
|
2018-10-02 07:41:19 +00:00
|
|
|
[
|
|
|
|
'<navigation></navigation>',
|
2019-02-02 22:34:48 +00:00
|
|
|
[ 'value' => '', 'item-name' => null ]
|
2018-10-02 07:41:19 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<navigation>kjdflkja dafkjlsdkfj</navigation>',
|
2019-02-02 22:34:48 +00:00
|
|
|
[ 'value' => 'kjdflkja dafkjlsdkfj', 'item-name' => null ]
|
2018-10-02 07:41:19 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<navigation>kjdflkja<ref>dafkjlsdkfj</ref></navigation>',
|
2019-02-02 22:34:48 +00:00
|
|
|
[ 'value' => 'kjdflkja<ref>dafkjlsdkfj</ref>', 'item-name' => null ]
|
2019-02-03 16:49:06 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<navigation name="ihatetests">kjdflkja dafkjlsdkfj</navigation>',
|
|
|
|
[ 'value' => 'kjdflkja dafkjlsdkfj', 'item-name' => 'ihatetests' ]
|
2018-10-02 07:41:19 +00:00
|
|
|
]
|
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 );
|
2022-03-11 20:35:51 +00:00
|
|
|
$node = new 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 [
|
|
|
|
[
|
2015-07-01 14:19:31 +00:00
|
|
|
'string' => '<navigation>goodnight</navigation>',
|
2015-05-20 14:38:23 +00:00
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
2015-07-01 14:19:31 +00:00
|
|
|
'string' => '<navigation>null</navigation>',
|
2015-05-20 14:38:23 +00:00
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
2015-07-01 14:19:31 +00:00
|
|
|
'string' => '<navigation>0</navigation>',
|
2015-05-20 14:57:43 +00:00
|
|
|
'expectedOutput' => false
|
|
|
|
],
|
|
|
|
[
|
2015-07-01 14:19:31 +00:00
|
|
|
'string' => '<navigation>\'0\'</navigation>',
|
2015-05-20 14:57:43 +00:00
|
|
|
'expectedOutput' => false
|
2015-05-20 14:38:23 +00:00
|
|
|
],
|
|
|
|
[
|
2015-07-01 14:19:31 +00:00
|
|
|
'string' => '<navigation></navigation>',
|
2015-05-20 14:38:23 +00:00
|
|
|
'expectedOutput' => true
|
|
|
|
],
|
|
|
|
[
|
2015-07-01 14:19:31 +00:00
|
|
|
'string' => '<navigation> </navigation>',
|
2015-05-20 14:38:23 +00:00
|
|
|
'expectedOutput' => true
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2017-03-15 18:07:51 +00:00
|
|
|
}
|