setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php'; parent::setUp(); } public function testNodeTitle() { $string = '<default>def</default>'; $xml = simplexml_load_string( $string ); $node = new Wikia\PortableInfobox\Parser\Nodes\NodeTitle( $xml, [ 'nombre' => 1 ] ); $nodeDefault = new Wikia\PortableInfobox\Parser\Nodes\NodeTitle( $xml, [ ] ); $this->assertTrue( $node->getData()[ 'value' ] == 1 ); $this->assertTrue( $nodeDefault->getData()[ 'value' ] == 'def' ); } public function testNodeData() { $string = 'Lorem ipsum'; $xml = simplexml_load_string( $string ); $node = new Wikia\PortableInfobox\Parser\Nodes\NodeData( $xml, [ 'Season' => 1 ] ); $nodeDefault = new Wikia\PortableInfobox\Parser\Nodes\NodeData( $xml, [ ] ); $this->assertTrue( $node->getData()[ 'value' ] == 1 ); $this->assertTrue( $nodeDefault->getData()[ 'value' ] == 'Lorem ipsum' ); } public function testNodeImage() { $string = 'default-alt'; $xml = simplexml_load_string( $string ); $nodeDefault = new Wikia\PortableInfobox\Parser\Nodes\NodeImage( $xml, [ ] ); $node = $this->getMockBuilder( 'Wikia\PortableInfobox\Parser\Nodes\NodeImage' )->setConstructorArgs( [ $xml, [ 'image2' => 'aaa.jpg', 'alt-source' => 'bbb' ] ] )->setMethods( [ 'resolveImageUrl' ] )->getMock(); $node->expects( $this->any() )->method( 'resolveImageUrl' )->will( $this->returnValue( 'aaa.jpg' ) ); $this->assertTrue( $node->getData()[ 'url' ] == 'aaa.jpg', 'value is not aaa.jpg' ); $this->assertTrue( $node->getData()[ 'name' ] == 'aaa.jpg', 'value is not aaa.jpg' ); $this->assertTrue( $node->getData()[ 'alt' ] == 'bbb', 'alt is not bbb' ); $this->assertTrue( $nodeDefault->getData()[ 'alt' ] == 'default-alt', 'default alt' ); } public function testNodeHeader() { $string = '
Comandantes
'; $xml = simplexml_load_string( $string ); $node = new Wikia\PortableInfobox\Parser\Nodes\NodeHeader( $xml, [ ] ); $this->assertTrue( $node->getData()[ 'value' ] == 'Comandantes' ); } public function testNodeFooter() { $string = ''; $xml = simplexml_load_string( $string ); $node = new Wikia\PortableInfobox\Parser\Nodes\NodeFooter( $xml, [ ] ); $this->assertTrue( $node->getData()[ 'value' ] == '123' ); } public function testNodeGroup() { $string = ' def1 def2 '; $xml = simplexml_load_string( $string ); $node = new Wikia\PortableInfobox\Parser\Nodes\NodeGroup( $xml, [ 'elem1' => 1, 'elem2' => 2 ] ); $data = $node->getData(); $this->assertTrue( is_array( $data[ 'value' ] ), 'value is array' ); $this->assertTrue( $data[ 'value' ][ 0 ][ 'data' ][ 'value' ] == 1, 'first elem' ); $this->assertTrue( $data[ 'value' ][ 1 ][ 'data' ][ 'value' ] == 2, 'second elem' ); $this->assertTrue( $data[ 'value' ][ 1 ][ 'data' ][ 'label' ] == 'l2', 'second elem - label' ); $this->assertTrue( $data[ 'value' ][ 2 ][ 'isNotEmpty' ] == false, 'empty' ); } public function testNodeComparition() { $string = '
Combatientes
Comandantes
'; $xml = simplexml_load_string( $string ); $node = new Wikia\PortableInfobox\Parser\Nodes\NodeComparison( $xml, [ 'lado1' => 1, 'lado2' => 2 ] ); $data = $node->getData(); $this->assertTrue( is_array( $data[ 'value' ] ), 'value is array' ); $this->assertTrue( $data[ 'value' ][ 0 ]['data']['value'][ 0 ][ 'type' ] == 'header' ); $this->assertTrue( $data[ 'value' ][ 0 ]['data']['value'][ 0 ][ 'data' ][ 'value' ] == 'Combatientes' ); $this->assertTrue( $data[ 'value' ][ 0 ]['data']['value'][ 1 ][ 'type' ] == 'data' ); $this->assertTrue( $data[ 'value' ][ 0 ]['data']['value'][ 2 ][ 'data' ][ 'value' ] == 2 ); } }