2015-06-15 12:57:57 +00:00
|
|
|
<?php
|
2018-08-08 09:42:22 +00:00
|
|
|
/**
|
|
|
|
* @group PortableInfobox
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeGroup
|
2018-08-08 09:42:22 +00:00
|
|
|
*/
|
|
|
|
class NodeGroupTest extends MediaWikiTestCase {
|
2015-06-15 12:58:48 +00:00
|
|
|
|
2015-10-28 17:55:03 +00:00
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeGroup::getData
|
2015-10-28 17:55:03 +00:00
|
|
|
* @dataProvider groupNodeCollapseTestProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testNodeGroupCollapse( $markup, $expected ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup );
|
2018-08-16 09:25:53 +00:00
|
|
|
$this->assertEquals( $expected, $node->getData()['collapse'] );
|
2015-10-28 17:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeGroup::getData
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeGroup::getRenderData
|
2017-01-10 12:05:22 +00:00
|
|
|
* @dataProvider groupNodeRowItemsTestProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testNodeGroupRowItems( $markup, $expected ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup );
|
2018-08-16 09:25:53 +00:00
|
|
|
$this->assertEquals( $expected, $node->getData()['row-items'] );
|
|
|
|
$this->assertEquals( $expected, $node->getRenderData()['data']['row-items'] );
|
2017-01-10 12:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
2018-08-09 09:49:10 +00:00
|
|
|
* @covers 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 ) {
|
2018-08-09 09:49:10 +00:00
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
2015-06-15 12:58:48 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getData() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function groupNodeTestProvider() {
|
|
|
|
return [
|
2018-10-02 07:41:19 +00:00
|
|
|
[
|
|
|
|
'<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,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l1',
|
|
|
|
'value' => 1,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem1',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'source' => [ 'elem1' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l2',
|
|
|
|
'value' => 2,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem2',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'source' => [ 'elem2' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => true,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l2',
|
|
|
|
'value' => null,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem3',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'source' => [ 'elem3' ]
|
|
|
|
]
|
2015-06-15 12:58:48 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'layout' => 'default',
|
|
|
|
'collapse' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'row-items' => null,
|
|
|
|
'item-name' => null
|
2018-10-02 07:41:19 +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' => [
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l1',
|
|
|
|
'value' => 1,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem1',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'source' => [ 'elem1' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l2',
|
|
|
|
'value' => 2,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem2',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'source' => [ 'elem2' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => true,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l2',
|
|
|
|
'value' => null,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem3',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'source' => [ 'elem3' ]
|
|
|
|
],
|
2015-06-15 12:58:48 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'layout' => 'horizontal',
|
|
|
|
'collapse' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'row-items' => null,
|
|
|
|
'item-name' => null
|
2018-10-02 07:41:19 +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' => [
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l1',
|
|
|
|
'value' => 1,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem1',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
|
|
|
'source' => [ 'elem1' ]
|
2018-10-02 07:41:19 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l2',
|
|
|
|
'value' => 2,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem2',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
|
|
|
'source' => [ 'elem2' ]
|
2018-10-02 07:41:19 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'isEmpty' => true,
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'label' => 'l2',
|
|
|
|
'value' => null,
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => 'elem3',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'source' => [ 'elem3' ]
|
|
|
|
]
|
2015-06-15 12:58:48 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'layout' => 'default',
|
|
|
|
'collapse' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'row-items' => null,
|
|
|
|
'item-name' => null
|
2018-10-02 07:41:19 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>',
|
|
|
|
[ '1' => 'one', '2' => 'two' ],
|
|
|
|
[
|
|
|
|
'value' => [
|
|
|
|
[
|
|
|
|
'type' => 'header',
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
2019-02-02 22:34:48 +00:00
|
|
|
'value' => 'h',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => []
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'value' => 'one',
|
|
|
|
'label' => '',
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => '1',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => [ '1' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'value' => 'two',
|
|
|
|
'label' => '',
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => '2',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => [ '2' ]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'layout' => 'default',
|
|
|
|
'collapse' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'row-items' => null,
|
|
|
|
'item-name' => null
|
2018-10-02 07:41:19 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>',
|
|
|
|
[ '1' => 'one' ],
|
|
|
|
[
|
|
|
|
'value' => [
|
|
|
|
[
|
|
|
|
'type' => 'header',
|
2019-02-02 22:34:48 +00:00
|
|
|
'data' => [ 'value' => 'h', 'item-name' => null ],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => []
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'value' => 'one',
|
|
|
|
'label' => '',
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => '1',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => [ '1' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'value' => null,
|
|
|
|
'label' => '',
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => '2',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => true,
|
|
|
|
'source' => [ '2' ]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'layout' => 'default',
|
|
|
|
'collapse' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'row-items' => null,
|
|
|
|
'item-name' => null
|
2018-10-02 07:41:19 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'<group show="incomplete"><header>h</header><data source="1"/><data source="2"/></group>',
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
'value' => [
|
|
|
|
[
|
|
|
|
'type' => 'header',
|
2019-02-02 22:34:48 +00:00
|
|
|
'data' => [
|
|
|
|
'value' => 'h',
|
|
|
|
'item-name' => null
|
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => []
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'value' => null,
|
|
|
|
'label' => '',
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => '1',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => true,
|
|
|
|
'source' => [ '1' ]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
2018-12-27 01:01:19 +00:00
|
|
|
'data' => [
|
|
|
|
'value' => null,
|
|
|
|
'label' => '',
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'source' => '2',
|
|
|
|
'item-name' => null
|
2018-12-27 01:01:19 +00:00
|
|
|
],
|
2018-10-02 07:41:19 +00:00
|
|
|
'isEmpty' => true,
|
|
|
|
'source' => [ '2' ]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'layout' => 'default',
|
|
|
|
'collapse' => null,
|
2019-02-02 22:34:48 +00:00
|
|
|
'row-items' => null,
|
|
|
|
'item-name' => null
|
2018-10-02 07:41:19 +00:00
|
|
|
]
|
2019-02-03 16:49:06 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'<group name="g"><header name="h">h</header><data source="d" name="d"/></group>',
|
|
|
|
[ 'd' => 'data' ],
|
|
|
|
[
|
|
|
|
'value' => [
|
|
|
|
[
|
|
|
|
'type' => 'header',
|
|
|
|
'data' => [
|
|
|
|
'value' => 'h',
|
|
|
|
'item-name' => 'h'
|
|
|
|
],
|
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => []
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'data',
|
|
|
|
'data' => [
|
|
|
|
'value' => 'data',
|
|
|
|
'label' => '',
|
|
|
|
'span' => 1,
|
|
|
|
'layout' => null,
|
|
|
|
'source' => 'd',
|
|
|
|
'item-name' => 'd'
|
|
|
|
],
|
|
|
|
'isEmpty' => false,
|
|
|
|
'source' => [ 'd' ]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'layout' => 'default',
|
|
|
|
'collapse' => null,
|
|
|
|
'row-items' => null,
|
|
|
|
'item-name' => 'g'
|
|
|
|
]
|
2018-10-02 07:41:19 +00:00
|
|
|
]
|
2015-06-15 12:58:48 +00:00
|
|
|
];
|
|
|
|
}
|
2018-08-16 09:25:53 +00:00
|
|
|
}
|