2015-04-27 14:05:31 +00:00
|
|
|
<?php
|
|
|
|
class PortableInfoboxParserNodesTest extends WikiaBaseTest {
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
require_once( dirname( __FILE__ ) . '/../PortableInfobox.setup.php' );
|
|
|
|
foreach ( $wgAutoloadClasses as $class => $file) {
|
|
|
|
require_once($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNodeTitle() {
|
|
|
|
$string = '<title source="nombre"><default>def</default></title>';
|
|
|
|
$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' );
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:48:57 +00:00
|
|
|
public function testNodeData() {
|
|
|
|
$string = '<data source="Season"><label>Season(s)</label><default>Lorem ipsum</default></data>';
|
2015-04-27 14:05:31 +00:00
|
|
|
$xml = simplexml_load_string( $string );
|
|
|
|
|
2015-05-04 10:48:57 +00:00
|
|
|
$node = new Wikia\PortableInfobox\Parser\Nodes\NodeData( $xml, [ 'Season' => 1 ] );
|
|
|
|
$nodeDefault = new Wikia\PortableInfobox\Parser\Nodes\NodeData( $xml, [ ] );
|
2015-04-27 14:05:31 +00:00
|
|
|
$this->assertTrue( $node->getData()[ 'value' ] == 1 );
|
|
|
|
$this->assertTrue( $nodeDefault->getData()[ 'value' ] == 'Lorem ipsum' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNodeImage() {
|
|
|
|
$string = '<image source="image2"><alt source="alt-source"><default>default-alt</default></alt></image>';
|
|
|
|
$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()[ 'value' ] == '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() {
|
2015-05-04 12:45:06 +00:00
|
|
|
$string = '<header>Comandantes</header>';
|
2015-04-27 14:05:31 +00:00
|
|
|
$xml = simplexml_load_string( $string );
|
|
|
|
|
|
|
|
$node = new Wikia\PortableInfobox\Parser\Nodes\NodeHeader( $xml, [ ] );
|
|
|
|
$this->assertTrue( $node->getData()[ 'value' ] == 'Comandantes' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNodeFooter() {
|
|
|
|
$string = '<footer><links>123</links></footer>';
|
|
|
|
$xml = simplexml_load_string( $string );
|
|
|
|
|
|
|
|
$node = new Wikia\PortableInfobox\Parser\Nodes\NodeFooter( $xml, [ ] );
|
|
|
|
$this->assertTrue( $node->getData()[ 'links' ] == '123' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNodeGroup() {
|
|
|
|
$string = '<group>
|
2015-05-04 10:48:57 +00:00
|
|
|
<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>
|
2015-04-27 14:05:31 +00:00
|
|
|
</group>
|
|
|
|
';
|
|
|
|
$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 = '<comparison>
|
|
|
|
<set>
|
2015-05-04 11:55:52 +00:00
|
|
|
<header>Combatientes</header>
|
2015-05-04 12:45:06 +00:00
|
|
|
<data source="lado1" />
|
|
|
|
<data source="lado2" />
|
2015-04-27 14:05:31 +00:00
|
|
|
</set>
|
|
|
|
<set>
|
2015-05-04 11:55:52 +00:00
|
|
|
<header>Comandantes</header>
|
2015-05-04 12:45:06 +00:00
|
|
|
<data source="comandantes1" />
|
|
|
|
<data source="comandantes2" />
|
2015-04-27 14:05:31 +00:00
|
|
|
</set>
|
|
|
|
</comparison>
|
|
|
|
';
|
|
|
|
$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' );
|
2015-05-04 10:48:57 +00:00
|
|
|
$this->assertTrue( $data[ 'value' ][ 0 ]['data']['value'][ 1 ][ 'type' ] == 'data' );
|
2015-04-27 14:05:31 +00:00
|
|
|
$this->assertTrue( $data[ 'value' ][ 0 ]['data']['value'][ 2 ][ 'data' ][ 'value' ] == 2 );
|
|
|
|
}
|
|
|
|
}
|