2015-06-15 12:57:57 +00:00
|
|
|
<?php
|
2015-06-15 12:58:48 +00:00
|
|
|
|
|
|
|
class NodeGroupTest extends WikiaBaseTest {
|
2015-07-03 10:16:18 +00:00
|
|
|
protected function groupUp() {
|
|
|
|
$this->groupupFile = dirname( __FILE__ ) . '/../../PortableInfobox.groupup.php';
|
|
|
|
parent::groupUp();
|
2015-06-15 12:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-03 10:16:18 +00:00
|
|
|
* @covers 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' =>
|
|
|
|
[
|
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l1', 'value' => 1 ],
|
|
|
|
'source' => [ 'elem1' ] ],
|
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l2', 'value' => 2 ],
|
|
|
|
'source' => [ 'elem2' ] ],
|
|
|
|
[ 'type' => 'data', 'isEmpty' => true, 'data' => [ 'label' => 'l2', 'value' => null ],
|
|
|
|
'source' => [ 'elem3' ] ]
|
|
|
|
],
|
|
|
|
'layout' => 'default'
|
|
|
|
] ],
|
|
|
|
[ '<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' =>
|
|
|
|
[
|
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l1', 'value' => 1 ],
|
|
|
|
'source' => [ 'elem1' ] ],
|
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l2', 'value' => 2 ],
|
|
|
|
'source' => [ 'elem2' ] ],
|
|
|
|
[ 'type' => 'data', 'isEmpty' => true, 'data' => [ 'label' => 'l2', 'value' => null ],
|
|
|
|
'source' => [ 'elem3' ] ],
|
|
|
|
],
|
|
|
|
'layout' => 'horizontal'
|
|
|
|
] ],
|
|
|
|
[ '<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' =>
|
|
|
|
[
|
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l1', 'value' => 1 ],
|
|
|
|
'source' => [ 'elem1' ] ],
|
|
|
|
[ 'type' => 'data', 'isEmpty' => false, 'data' => [ 'label' => 'l2', 'value' => 2 ],
|
|
|
|
'source' => [ 'elem2' ] ],
|
|
|
|
[ 'type' => 'data', 'isEmpty' => true, 'data' => [ 'label' => 'l2', 'value' => null ],
|
|
|
|
'source' => [ 'elem3' ] ],
|
|
|
|
],
|
|
|
|
'layout' => 'default'
|
|
|
|
] ],
|
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' => [ ] ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'one', 'label' => '' ], 'isEmpty' => false,
|
|
|
|
'source' => [ '1' ] ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'two', 'label' => '' ], 'isEmpty' => false,
|
|
|
|
'source' => [ '2' ] ],
|
|
|
|
],
|
|
|
|
'layout' => 'default'
|
|
|
|
] ],
|
|
|
|
[ '<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>',
|
|
|
|
[ '1' => 'one' ],
|
|
|
|
[ 'value' => [
|
|
|
|
[ 'type' => 'header', 'data' => [ 'value' => 'h' ], 'isEmpty' => false, 'source' => [ ] ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => 'one', 'label' => '' ], 'isEmpty' => false,
|
|
|
|
'source' => [ '1' ] ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => null, 'label' => '' ], 'isEmpty' => true,
|
|
|
|
'source' => [ '2' ] ]
|
|
|
|
],
|
|
|
|
'layout' => 'default'
|
|
|
|
] ],
|
|
|
|
[ '<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>', [ ],
|
|
|
|
[ 'value' => [
|
|
|
|
[ 'type' => 'header', 'data' => [ 'value' => 'h' ], 'isEmpty' => false, 'source' => [ ] ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => null, 'label' => '' ], 'isEmpty' => true,
|
|
|
|
'source' => [ '1' ] ],
|
|
|
|
[ 'type' => 'data', 'data' => [ 'value' => null, 'label' => '' ], 'isEmpty' => true,
|
|
|
|
'source' => [ '2' ] ],
|
|
|
|
],
|
|
|
|
'layout' => 'default'
|
|
|
|
] ]
|
2015-06-15 12:58:48 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|