2015-06-15 12:57:57 +00:00
|
|
|
<?php
|
2015-06-15 12:58:48 +00:00
|
|
|
|
|
|
|
class NodeGroupTest extends WikiaBaseTest {
|
2015-07-01 15:34:41 +00:00
|
|
|
protected function setUp() {
|
|
|
|
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
|
|
|
parent::setUp();
|
2015-06-15 12:58:48 +00:00
|
|
|
}
|
|
|
|
|
2015-10-28 17:55:03 +00:00
|
|
|
/**
|
2016-02-25 15:51:47 +00:00
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeGroup::getData
|
2015-10-28 17:55:03 +00:00
|
|
|
* @dataProvider groupNodeCollapseTestProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testNodeGroupCollapse( $markup, $expected ) {
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup );
|
|
|
|
$this->assertEquals( $expected, $node->getData()[ 'collapse' ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function groupNodeCollapseTestProvider() {
|
|
|
|
return [
|
|
|
|
[ '<group></group>', null ],
|
|
|
|
[ '<group collapse="wrong"></group>', null ],
|
|
|
|
[ '<group collapse="open"></group>', 'open' ],
|
|
|
|
[ '<group collapse="closed"></group>', 'closed' ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-01-10 12:05:22 +00:00
|
|
|
/**
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeGroup::getData
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeGroup::getRenderData
|
|
|
|
* @dataProvider groupNodeRowItemsTestProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testNodeGroupRowItems( $markup, $expected ) {
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup );
|
|
|
|
$this->assertEquals( $expected, $node->getData()[ 'row-items' ] );
|
|
|
|
$this->assertEquals( $expected, $node->getRenderData()[ 'data' ][ 'row-items' ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function groupNodeRowItemsTestProvider() {
|
|
|
|
return [
|
|
|
|
[ '<group></group>', null ],
|
|
|
|
[ '<group row-items="not a number"></group>', null ],
|
|
|
|
[ '<group row-items="5.5"></group>', null ],
|
|
|
|
[ '<group row-items="5"></group>', '5' ],
|
|
|
|
[ '<group row-items="50"></group>', '50' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-15 12:58:48 +00:00
|
|
|
/**
|
2016-02-25 15:51:47 +00:00
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeGroup::getData
|
2015-06-15 12:58:48 +00:00
|
|
|
* @dataProvider groupNodeTestProvider
|
2015-07-03 10:16:18 +00:00
|
|
|
*
|
2015-06-15 12:58:48 +00:00
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testNodeGroup( $markup, $params, $expected ) {
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getData() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function groupNodeTestProvider() {
|
|
|
|
return [
|
|
|
|
[ '<group><data source="elem1"><label>l1</label><default>def1</default></data><data source="elem2">
|
|
|
|
<label>l2</label><default>def2</default></data><data source="elem3"><label>l2</label></data></group>',
|
|
|
|
[ 'elem1' => 1, 'elem2' => 2 ],
|
|
|
|
[ 'value' =>
|
|
|
|
[
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l1', 'value' => 1, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem1' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l2', 'value' => 2, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem2' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => true, 'data' => [ 'label' => 'l2', 'value' => null, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem3' ] ]
|
|
|
|
],
|
2015-10-26 22:06:10 +00:00
|
|
|
'layout' => 'default',
|
2017-01-10 12:05:22 +00:00
|
|
|
'collapse' => null,
|
|
|
|
'row-items' => null
|
2015-06-15 12:58:48 +00:00
|
|
|
] ],
|
|
|
|
[ '<group layout="horizontal"><data source="elem1"><label>l1</label><default>def1</default></data><data source="elem2">
|
|
|
|
<label>l2</label><default>def2</default></data><data source="elem3"><label>l2</label></data></group>',
|
|
|
|
[ 'elem1' => 1, 'elem2' => 2 ],
|
|
|
|
[ 'value' =>
|
|
|
|
[
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l1', 'value' => 1, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem1' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l2', 'value' => 2, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem2' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => true, 'data' => [ 'label' => 'l2', 'value' => null, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem3' ] ],
|
|
|
|
],
|
2015-10-26 22:06:10 +00:00
|
|
|
'layout' => 'horizontal',
|
2017-01-10 12:05:22 +00:00
|
|
|
'collapse' => null,
|
|
|
|
'row-items' => null
|
2015-06-15 12:58:48 +00:00
|
|
|
] ],
|
|
|
|
[ '<group layout="loool"><data source="elem1"><label>l1</label><default>def1</default></data><data source="elem2">
|
|
|
|
<label>l2</label><default>def2</default></data><data source="elem3"><label>l2</label></data></group>',
|
|
|
|
[ 'elem1' => 1, 'elem2' => 2 ],
|
|
|
|
[ 'value' =>
|
|
|
|
[
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l1', 'value' => 1, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem1' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l2', 'value' => 2, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem2' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'isEmpty' => true, 'data' => [ 'label' => 'l2', 'value' => null, 'span' => 1, 'layout' => null ],
|
2015-06-15 12:58:48 +00:00
|
|
|
'source' => [ 'elem3' ] ],
|
|
|
|
],
|
2015-10-26 22:06:10 +00:00
|
|
|
'layout' => 'default',
|
2017-01-10 12:05:22 +00:00
|
|
|
'collapse' => null,
|
|
|
|
'row-items' => null
|
2015-06-15 12:58:48 +00:00
|
|
|
] ],
|
2015-07-03 10:16:18 +00:00
|
|
|
[ '<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>',
|
|
|
|
[ '1' => 'one', '2' => 'two' ],
|
|
|
|
[ 'value' => [
|
|
|
|
[ 'type' => 'header', 'data' => [ 'value' => 'h' ], 'isEmpty' => false, 'source' => [ ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'one', 'label' => '', 'span' => 1, 'layout' => null ], 'isEmpty' => false,
|
2015-07-03 10:16:18 +00:00
|
|
|
'source' => [ '1' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'two', 'label' => '', 'span' => 1, 'layout' => null ], 'isEmpty' => false,
|
2015-07-03 10:16:18 +00:00
|
|
|
'source' => [ '2' ] ],
|
|
|
|
],
|
2015-10-26 22:06:10 +00:00
|
|
|
'layout' => 'default',
|
2017-01-10 12:05:22 +00:00
|
|
|
'collapse' => null,
|
|
|
|
'row-items' => null
|
2015-07-03 10:16:18 +00:00
|
|
|
] ],
|
|
|
|
[ '<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>',
|
|
|
|
[ '1' => 'one' ],
|
|
|
|
[ 'value' => [
|
|
|
|
[ 'type' => 'header', 'data' => [ 'value' => 'h' ], 'isEmpty' => false, 'source' => [ ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'one', 'label' => '', 'span' => 1, 'layout' => null ], 'isEmpty' => false,
|
2015-07-03 10:16:18 +00:00
|
|
|
'source' => [ '1' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => null, 'label' => '', 'span' => 1, 'layout' => null ], 'isEmpty' => true,
|
2015-07-03 10:16:18 +00:00
|
|
|
'source' => [ '2' ] ]
|
|
|
|
],
|
2015-10-26 22:06:10 +00:00
|
|
|
'layout' => 'default',
|
2017-01-10 12:05:22 +00:00
|
|
|
'collapse' => null,
|
|
|
|
'row-items' => null
|
|
|
|
|
2015-07-03 10:16:18 +00:00
|
|
|
] ],
|
|
|
|
[ '<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>', [ ],
|
|
|
|
[ 'value' => [
|
|
|
|
[ 'type' => 'header', 'data' => [ 'value' => 'h' ], 'isEmpty' => false, 'source' => [ ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => null, 'label' => '', 'span' => 1, 'layout' => null ], 'isEmpty' => true,
|
2015-07-03 10:16:18 +00:00
|
|
|
'source' => [ '1' ] ],
|
2017-01-10 12:59:46 +00:00
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => null, 'label' => '', 'span' => 1, 'layout' => null ], 'isEmpty' => true,
|
2015-07-03 10:16:18 +00:00
|
|
|
'source' => [ '2' ] ],
|
|
|
|
],
|
2015-10-26 22:06:10 +00:00
|
|
|
'layout' => 'default',
|
2017-01-10 12:05:22 +00:00
|
|
|
'collapse' => null,
|
|
|
|
'row-items' => null
|
2015-07-03 10:16:18 +00:00
|
|
|
] ]
|
2015-06-15 12:58:48 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|