diff --git a/services/Parser/Nodes/Node.php b/services/Parser/Nodes/Node.php
index f2c415d..db57498 100644
--- a/services/Parser/Nodes/Node.php
+++ b/services/Parser/Nodes/Node.php
@@ -178,14 +178,6 @@ class Node {
: null;
}
- protected function getXmlAttributeFromSupported( \SimpleXMLElement $xmlNode, $attribute, $supportedAttributes ) {
- $attr = $this->getXmlAttribute( $xmlNode, $attribute );
- if ( isset($attr) && in_array( $attr, $supportedAttributes ) ) {
- return $attr;
- }
- return static::DEFAULT_TAG_NAME;
- }
-
protected function getRawInfoboxData( $key ) {
return isset( $this->infoboxData[ $key ] ) ? $this->infoboxData[ $key ]
: null;
diff --git a/services/Parser/Nodes/NodeGroup.php b/services/Parser/Nodes/NodeGroup.php
index 09a8569..37bf6b0 100644
--- a/services/Parser/Nodes/NodeGroup.php
+++ b/services/Parser/Nodes/NodeGroup.php
@@ -13,8 +13,7 @@ class NodeGroup extends Node {
public function getData() {
if ( !isset( $this->data ) ) {
$this->data = [ 'value' => $this->getDataForChildren(),
- 'layout' => $this->getXmlAttributeFromSupported( $this->xmlNode,
- self::DATA_LAYOUT_ATTR_NAME, $this->supportedGroupLayouts) ];
+ 'layout' => $this->getLayout() ];
}
return $this->data;
@@ -23,9 +22,8 @@ class NodeGroup extends Node {
public function getRenderData() {
return [
'type' => $this->getType(),
- 'data' => [ 'value' => $this->getRenderDataForChildren(),
- 'layout' => $this->getXmlAttributeFromSupported( $this->xmlNode,
- self::DATA_LAYOUT_ATTR_NAME, $this->supportedGroupLayouts) ],
+ 'data' => [ 'value' => $this->getRenderDataForChildren(),
+ 'layout' => $this->getLayout() ],
];
}
@@ -43,4 +41,14 @@ class NodeGroup extends Node {
public function getSource() {
return $this->getSourceForChildren();
}
+
+ /**
+ * @return string
+ */
+ protected function getLayout() {
+ $layout = $this->getXmlAttribute( $this->xmlNode, self::DATA_LAYOUT_ATTR_NAME );
+
+ return ( isset( $layout ) && in_array( $layout, $this->supportedGroupLayouts ) ) ? $layout
+ : self::DEFAULT_TAG_NAME;
+ }
}
diff --git a/tests/nodes/NodeGroupTest.php b/tests/nodes/NodeGroupTest.php
index d409d0e..01b3348 100644
--- a/tests/nodes/NodeGroupTest.php
+++ b/tests/nodes/NodeGroupTest.php
@@ -1,7 +1,68 @@
setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
+ parent::setUp();
+ }
+
+ /**
+ * @covers NodeGroup::getData
+ * @dataProvider groupNodeTestProvider
+ * @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 [
+ [ 'def1
+ def2',
+ [ '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'
+ ] ],
+ [ 'def1
+ def2',
+ [ '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'
+ ] ],
+ [ 'def1
+ def2',
+ [ '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'
+ ] ],
+ ];
+ }
+}
\ No newline at end of file