setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php'; parent::setUp(); } /** * @covers NodeComparison::getData * @covers Node::getDataForChildren * @covers Node::getChildNodes * @dataProvider dataProvider * * @param $markup * @param $params * @param $expected */ public function testGetData( $markup, $params, $expected ) { $node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $this->assertEquals( $expected, $node->getData() ); } public function dataProvider() { return [ [ '', [ '1' => 'one', '2' => 'two' ], [ 'value' => [ [ 'type' => 'set', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'one' ], 'isEmpty' => false, 'source' => [ '1' ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'two' ], 'isEmpty' => false, 'source' => [ '2' ] ] ] ], 'isEmpty' => false, 'source' => [ '1', '2' ] ] ] ] ], [ '', [ ], [ 'value' => [ [ 'type' => 'set', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => null ], 'isEmpty' => true, 'source' => [ '1' ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => null ], 'isEmpty' => true, 'source' => [ '2' ] ] ] ], 'isEmpty' => true, 'source' => [ '1', '2' ] ] ] ] ], [ '', [ '1' => 'one' ], [ 'value' => [ [ 'type' => 'set', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'one' ], 'isEmpty' => false, 'source' => [ '1' ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => null ], 'isEmpty' => true, 'source' => [ '2' ] ] ] ], 'isEmpty' => false, 'source' => [ '1', '2' ] ] ] ] ], [ '', [ '1' => 'one' ], [ 'value' => [ [ 'type' => 'data', 'data' => [ 'value' => 'one', 'label' => 'Test' ], 'isEmpty' => false, 'source' => [ '1' ] ] ] ] ] ]; } /** * @covers NodeComparison::getRenderData * @covers Node::getRenderDataForChildren * @dataProvider renderDataProvider * * @param $markup * @param $params * @param $expected */ public function testRenderData( $markup, $params, $expected ) { $node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params ); $this->assertEquals( $expected, $node->getRenderData() ); } public function renderDataProvider() { return [ [ '', [ '1' => 'one', '2' => 'two' ], [ 'type' => 'comparison', 'data' => [ 'value' => [ [ 'type' => 'set', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'one' ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'two' ] ] ] ], ] ] ], ] ], [ '{{{1}}}', [ '1' => 'one', '2' => 'two' ], [ 'type' => 'comparison', 'data' => [ 'value' => [ [ 'type' => 'set', 'data' => [ 'value' => [ [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'one' ] ], [ 'type' => 'data', 'data' => [ 'label' => '', 'value' => 'two' ] ] ] ], ] ] ], ] ], ]; } /** * @covers NodeComparison::getSource * @covers Node::getSourceForChildren * @dataProvider sourceDataProvider * * @param string $markup XML to test * @param array $expected */ public function testSource( $markup, $expected ) { $node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] ); $this->assertEquals( $expected, $node->getSource() ); } public function sourceDataProvider() { return [ [ '', [ '1', '2' ] ], [ '', [ '1' ] ], [ '{{{def}}}', [ '2', 'def' ] ], [ '', [ ] ], ]; } /** * @dataProvider testIsEmptyDataProvider */ public function testIsEmpty( $val1, $val2, $val3, $expectedOutput ) { $string = '
Comparison1
Comparison2
'; $xml = simplexml_load_string( $string ); $node = new Wikia\PortableInfobox\Parser\Nodes\NodeComparison( $xml, [ 'val1' => $val1, 'val2' => $val2, 'val3' => $val3 ] ); $data = $node->getData(); $this->assertTrue( $node->isEmpty( $data ) == $expectedOutput ); } public function testIsEmptyDataProvider() { return [ [ 'val1' => 'yoda', 'val2' => 'obi-wan', 'val3' => null, 'expectedOutput' => false ], [ 'val1' => null, 'val2' => null, 'val3' => '0', 'expectedOutput' => false ], [ 'val1' => 12, 'val2' => 13, 'val3' => 55, 'expectedOutput' => false ], [ 'val1' => '0', 'val2' => '0', 'val3' => '0', 'expectedOutput' => false ], [ 'val1' => null, 'val2' => null, 'val3' => null, 'expectedOutput' => true ] ]; } }