2015-06-11 12:51:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class NodeImageTest extends WikiaBaseTest {
|
|
|
|
protected function setUp() {
|
|
|
|
$this->setupFile = dirname( __FILE__ ) . '/../../PortableInfobox.setup.php';
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers NodeImage::getData
|
|
|
|
* @dataProvider dataProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testData( $markup, $params, $expected ) {
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getData() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataProvider() {
|
|
|
|
return [
|
|
|
|
[ '<image source="img"></image>', [ ],
|
|
|
|
[ 'url' => '', 'name' => '', 'key' => '', 'alt' => null, 'caption' => null, 'ref' => null ] ],
|
|
|
|
[ '<image source="img"></image>', [ 'img' => 'test.jpg' ],
|
|
|
|
[ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => null, 'caption' => null, 'ref' => 0 ] ],
|
|
|
|
[ '<image source="img"><alt><default>test alt</default></alt></image>', [ 'img' => 'test.jpg' ],
|
|
|
|
[ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => null,
|
|
|
|
'ref' => 1 ] ],
|
|
|
|
[ '<image source="img"><alt source="alt source"><default>test alt</default></alt></image>',
|
|
|
|
[ 'img' => 'test.jpg', 'alt source' => 2 ],
|
|
|
|
[ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 2, 'caption' => null, 'ref' => 2 ] ],
|
|
|
|
[ '<image source="img"><alt><default>test alt</default></alt><caption source="img"/></image>',
|
|
|
|
[ 'img' => 'test.jpg' ],
|
|
|
|
[ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => 'test.jpg',
|
|
|
|
'ref' => 3 ] ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers NodeImage::isEmpty
|
|
|
|
* @dataProvider isEmptyProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $params
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testIsEmpty( $markup, $params, $expected ) {
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, $params );
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->isEmpty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isEmptyProvider() {
|
|
|
|
return [
|
|
|
|
[ '<image></image>', [ ], true ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers NodeImage::getSource
|
|
|
|
* @dataProvider sourceProvider
|
|
|
|
*
|
|
|
|
* @param $markup
|
|
|
|
* @param $expected
|
|
|
|
*/
|
|
|
|
public function testSource( $markup, $expected ) {
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] );
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getSource() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sourceProvider() {
|
|
|
|
return [
|
|
|
|
[ '<image source="img"/>', [ 'img' ] ],
|
2015-06-12 13:43:37 +00:00
|
|
|
[ '<image source="img"><default>{{{img}}}</default><alt source="img" /></image>', [ 'img' ] ],
|
2015-06-11 12:51:54 +00:00
|
|
|
[ '<image source="img"><alt source="alt"/><caption source="cap"/></image>', [ 'img', 'alt', 'cap' ] ],
|
|
|
|
[ '<image source="img"><alt source="alt"><default>{{{def}}}</default></alt><caption source="cap"/></image>',
|
|
|
|
[ 'img', 'alt', 'def', 'cap' ] ],
|
|
|
|
[ '<image/>', [ ] ],
|
|
|
|
];
|
|
|
|
}
|
2015-07-22 11:04:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider testVideoProvider
|
|
|
|
*/
|
|
|
|
public function testVideo( $markup, $params, $expected ) {
|
2015-07-22 13:15:08 +00:00
|
|
|
global $wgHooks;
|
|
|
|
|
|
|
|
// backup the hooks
|
|
|
|
$tmpHooks = $wgHooks['PortableInfoboxNodeImage::getData'];
|
|
|
|
$wgHooks['PortableInfoboxNodeImage::getData'] = [];
|
|
|
|
|
2015-07-22 11:04:41 +00:00
|
|
|
$fileMock = new FileMock();
|
2015-09-07 16:21:17 +00:00
|
|
|
$titleMock = new TitleMock();
|
2015-07-22 11:04:41 +00:00
|
|
|
$xmlObj = Wikia\PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
|
|
|
|
|
|
|
|
|
2015-07-22 13:15:08 +00:00
|
|
|
$this->mockStaticMethod( 'WikiaFileHelper', 'getFileFromTitle', $fileMock );
|
2015-09-07 16:21:17 +00:00
|
|
|
$this->mockStaticMethod( '\Title', 'makeTitleSafe', $titleMock );
|
2015-07-22 13:15:08 +00:00
|
|
|
$nodeImage = new Wikia\PortableInfobox\Parser\Nodes\NodeImage( $xmlObj, $params );
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $nodeImage->getData() );
|
2015-07-22 11:04:41 +00:00
|
|
|
|
2015-07-22 13:15:08 +00:00
|
|
|
// restore the hooks
|
|
|
|
$wgHooks['PortableInfoboxNodeImage::getData'] = $tmpHooks;
|
2015-07-22 11:04:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testVideoProvider() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'<image source="img" />',
|
|
|
|
[ 'img' => 'test.jpg' ],
|
|
|
|
[
|
2015-09-07 16:21:17 +00:00
|
|
|
'url' => 'http://test.url',
|
|
|
|
'name' => '',
|
|
|
|
'key' => '',
|
2015-07-22 11:04:41 +00:00
|
|
|
'alt' => null,
|
|
|
|
'caption' => null,
|
2015-09-07 16:21:17 +00:00
|
|
|
'ref' => null,
|
2015-07-22 11:04:41 +00:00
|
|
|
'isVideo' => true,
|
2015-07-22 13:15:08 +00:00
|
|
|
'duration' => '00:10'
|
2015-07-22 11:04:41 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FileMock {
|
|
|
|
public function getMediaType() {
|
|
|
|
return "VIDEO";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMetadataDuration() {
|
2015-07-22 13:15:08 +00:00
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUrl() {
|
|
|
|
return '';
|
2015-07-22 11:04:41 +00:00
|
|
|
}
|
2015-06-11 12:51:54 +00:00
|
|
|
}
|
2015-09-07 16:21:17 +00:00
|
|
|
|
|
|
|
class TitleMock {
|
|
|
|
public function getFullURL() {
|
|
|
|
return 'http://test.url';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getText() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDBKey() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|