2015-06-11 12:51:54 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2017-01-25 11:18:20 +00:00
|
|
|
|
use Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag;
|
|
|
|
|
use Wikia\PortableInfobox\Parser\Nodes\NodeImage;
|
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* @group PortableInfobox
|
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage
|
|
|
|
|
*/
|
|
|
|
|
class NodeImageTest extends MediaWikiTestCase {
|
|
|
|
|
|
2015-06-11 12:51:54 +00:00
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
2018-08-08 09:42:22 +00:00
|
|
|
|
|
|
|
|
|
global $wgUseInstantCommons;
|
|
|
|
|
$wgUseInstantCommons = false;
|
2015-06-11 12:51:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-20 22:42:36 +00:00
|
|
|
|
/**
|
2016-02-25 15:51:47 +00:00
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getGalleryData
|
2017-01-25 11:18:20 +00:00
|
|
|
|
* @dataProvider galleryDataProvider
|
|
|
|
|
* @param $marker
|
|
|
|
|
* @param $expected
|
2015-10-20 22:42:36 +00:00
|
|
|
|
*/
|
2017-01-25 11:18:20 +00:00
|
|
|
|
public function testGalleryData( $marker, $expected ) {
|
|
|
|
|
$this->assertEquals( $expected, NodeImage::getGalleryData( $marker ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function galleryDataProvider() {
|
|
|
|
|
$markers = [
|
|
|
|
|
"'\"`UNIQabcd-gAlLeRy-1-QINU`\"'",
|
|
|
|
|
"'\"`UNIQabcd-gAlLeRy-2-QINU`\"'",
|
|
|
|
|
"'\"`UNIQabcd-gAlLeRy-3-QINU`\"'"
|
|
|
|
|
];
|
|
|
|
|
PortableInfoboxDataBag::getInstance()->setGallery( $markers[0],
|
2018-08-08 09:42:22 +00:00
|
|
|
|
new GalleryMock([
|
2017-01-25 11:18:20 +00:00
|
|
|
|
[
|
2018-08-08 09:42:22 +00:00
|
|
|
|
'image0_name.jpg',
|
|
|
|
|
'image0_caption'
|
2017-01-25 11:18:20 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2018-08-08 09:42:22 +00:00
|
|
|
|
'image01_name.jpg',
|
|
|
|
|
'image01_caption'
|
2017-01-25 11:18:20 +00:00
|
|
|
|
],
|
2018-08-08 09:42:22 +00:00
|
|
|
|
]));
|
2017-01-25 11:18:20 +00:00
|
|
|
|
PortableInfoboxDataBag::getInstance()->setGallery( $markers[1],
|
2018-08-08 09:42:22 +00:00
|
|
|
|
new GalleryMock([
|
2017-01-25 11:18:20 +00:00
|
|
|
|
[
|
2018-08-08 09:42:22 +00:00
|
|
|
|
'image1_name.jpg',
|
|
|
|
|
'image1_caption'
|
2017-01-25 11:18:20 +00:00
|
|
|
|
]
|
2018-08-08 09:42:22 +00:00
|
|
|
|
]));
|
|
|
|
|
PortableInfoboxDataBag::getInstance()->setGallery( $markers[2], new GalleryMock() );
|
2017-01-25 11:18:20 +00:00
|
|
|
|
|
|
|
|
|
return [
|
2017-01-13 08:37:27 +00:00
|
|
|
|
[
|
2017-01-25 11:18:20 +00:00
|
|
|
|
'marker' => $markers[0],
|
|
|
|
|
'expected' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => 'image0_caption',
|
|
|
|
|
'title' => 'image0_name.jpg',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label' => 'image01_caption',
|
|
|
|
|
'title' => 'image01_name.jpg',
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'marker' => $markers[1],
|
|
|
|
|
'expected' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => 'image1_caption',
|
|
|
|
|
'title' => 'image1_name.jpg',
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'marker' => $markers[2],
|
|
|
|
|
'expected' => []
|
|
|
|
|
],
|
2017-01-02 13:31:45 +00:00
|
|
|
|
];
|
2015-10-20 22:42:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-25 15:51:47 +00:00
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getTabberData
|
2015-10-20 22:42:36 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testTabberData() {
|
2018-08-08 09:42:22 +00:00
|
|
|
|
$input = '<div class="tabber"><div class="tabbertab" title="_title_"><p><a><img src="_src_"></a></p></div></div>';
|
2017-01-02 13:31:45 +00:00
|
|
|
|
$expected = [
|
|
|
|
|
[
|
2015-10-20 22:42:36 +00:00
|
|
|
|
'label' => '_title_',
|
2018-08-08 09:42:22 +00:00
|
|
|
|
'title' => '_src_',
|
2017-01-02 13:31:45 +00:00
|
|
|
|
]
|
|
|
|
|
];
|
2017-01-25 11:18:20 +00:00
|
|
|
|
$this->assertEquals( $expected, NodeImage::getTabberData( $input ) );
|
2015-10-20 22:42:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-25 15:51:47 +00:00
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getMarkers
|
2015-10-20 22:42:36 +00:00
|
|
|
|
* @dataProvider markersProvider
|
2016-04-20 08:38:44 +00:00
|
|
|
|
* @param $ext
|
|
|
|
|
* @param $value
|
2015-10-20 22:42:36 +00:00
|
|
|
|
* @param $expected
|
|
|
|
|
*/
|
|
|
|
|
public function testMarkers( $ext, $value, $expected ) {
|
|
|
|
|
$this->assertEquals( $expected, Wikia\PortableInfobox\Parser\Nodes\NodeImage::getMarkers( $value, $ext ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markersProvider() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'TABBER',
|
2018-08-08 09:42:22 +00:00
|
|
|
|
"<div>\x7f'\"`UNIQ--tAbBeR-12345678-QINU`\"'\x7f</div>",
|
|
|
|
|
[ "\x7f'\"`UNIQ--tAbBeR-12345678-QINU`\"'\x7f" ]
|
2015-10-20 22:42:36 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'GALLERY',
|
2018-08-08 09:42:22 +00:00
|
|
|
|
"\x7f'\"`UNIQ--tAbBeR-12345678-QINU`\"'\x7f<center>\x7f'\"`UNIQ--gAlLeRy-12345678-QINU`\"'\x7f</center>\x7f'\"`UNIQ--gAlLeRy-87654321-QINU`\"'\x7f",
|
|
|
|
|
[ "\x7f'\"`UNIQ--gAlLeRy-12345678-QINU`\"'\x7f", "\x7f'\"`UNIQ--gAlLeRy-87654321-QINU`\"'\x7f" ]
|
2017-01-25 11:18:20 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'GALLERY',
|
2018-08-08 09:42:22 +00:00
|
|
|
|
"\x7f'\"`UNIQ--somethingelse-12345678-QINU`\"'\x7f",
|
2017-01-25 11:18:20 +00:00
|
|
|
|
[ ]
|
2015-10-20 22:42:36 +00:00
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-06-11 12:51:54 +00:00
|
|
|
|
/**
|
2016-02-25 15:51:47 +00:00
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getData
|
2015-06-11 12:51:54 +00:00
|
|
|
|
* @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() {
|
2015-10-20 21:28:27 +00:00
|
|
|
|
// markup, params, expected
|
2015-06-11 12:51:54 +00:00
|
|
|
|
return [
|
2016-04-20 08:38:44 +00:00
|
|
|
|
[
|
2015-10-20 21:28:27 +00:00
|
|
|
|
'<image source="img"></image>',
|
|
|
|
|
[ ],
|
2016-04-20 08:38:44 +00:00
|
|
|
|
[ [ 'url' => '', 'name' => '', 'key' => '', 'alt' => null, 'caption' => null, 'isVideo' => false ] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<image source="img"></image>',
|
|
|
|
|
[ 'img' => 'test.jpg' ],
|
2018-08-08 09:42:22 +00:00
|
|
|
|
[ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'Test.jpg', 'caption' => null, 'isVideo' => false ] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<image source="img"><alt><default>test alt</default></alt></image>',
|
|
|
|
|
[ 'img' => 'test.jpg' ],
|
2016-04-20 08:38:44 +00:00
|
|
|
|
[ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => null, 'isVideo' => false ] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<image source="img"><alt source="alt source"><default>test alt</default></alt></image>',
|
|
|
|
|
[ 'img' => 'test.jpg', 'alt source' => 2 ],
|
2016-04-20 08:38:44 +00:00
|
|
|
|
[ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 2, 'caption' => null, 'isVideo' => false ] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<image source="img"><alt><default>test alt</default></alt><caption source="img"/></image>',
|
|
|
|
|
[ 'img' => 'test.jpg' ],
|
2016-04-20 08:38:44 +00:00
|
|
|
|
[ [ 'url' => '', 'name' => 'Test.jpg', 'key' => 'Test.jpg', 'alt' => 'test alt', 'caption' => 'test.jpg', 'isVideo' => false ] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
2015-06-11 12:51:54 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-02-25 15:51:47 +00:00
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::isEmpty
|
2015-06-11 12:51:54 +00:00
|
|
|
|
* @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 ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-14 12:54:53 +00:00
|
|
|
|
* @covers \Wikia\PortableInfobox\Parser\Nodes\NodeImage::getSources
|
|
|
|
|
* @dataProvider sourcesProvider
|
2015-06-11 12:51:54 +00:00
|
|
|
|
*
|
|
|
|
|
* @param $markup
|
|
|
|
|
* @param $expected
|
|
|
|
|
*/
|
2016-12-14 12:54:53 +00:00
|
|
|
|
public function testSources( $markup, $expected ) {
|
2015-06-11 12:51:54 +00:00
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] );
|
|
|
|
|
|
2016-12-14 12:54:53 +00:00
|
|
|
|
$this->assertEquals( $expected, $node->getSources() );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 12:54:53 +00:00
|
|
|
|
public function sourcesProvider() {
|
2015-06-11 12:51:54 +00:00
|
|
|
|
return [
|
2015-10-20 21:30:07 +00:00
|
|
|
|
[
|
|
|
|
|
'<image source="img"/>',
|
|
|
|
|
[ 'img' ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<image source="img"><default>{{{img}}}</default><alt source="img" /></image>',
|
|
|
|
|
[ 'img' ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<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/>',
|
|
|
|
|
[ ]
|
|
|
|
|
],
|
2017-01-02 13:31:45 +00:00
|
|
|
|
[
|
|
|
|
|
'<image source="img"><caption source="cap"><format>Test {{{cap}}} and {{{fcap}}}</format></caption></image>',
|
|
|
|
|
[ 'img', 'cap', 'fcap' ]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @dataProvider metadataProvider */
|
|
|
|
|
public function testMetadata( $markup, $expected ) {
|
|
|
|
|
$node = \Wikia\PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [ ] );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getMetadata() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function metadataProvider() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'<image source="img"><caption source="cap"><format>Test {{{cap}}} and {{{fcap}}}</format></caption></image>',
|
|
|
|
|
[ 'type' => 'image', 'sources' => [
|
|
|
|
|
'img' => [ 'label' => '', 'primary' => true ],
|
|
|
|
|
'cap' => [ 'label' => '' ],
|
|
|
|
|
'fcap' => [ 'label' => '' ]
|
|
|
|
|
] ]
|
|
|
|
|
]
|
2015-06-11 12:51:54 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
2015-07-22 11:04:41 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2017-03-15 18:07:51 +00:00
|
|
|
|
* @dataProvider videoProvider
|
2016-04-20 08:38:44 +00:00
|
|
|
|
* @param $markup
|
|
|
|
|
* @param $params
|
|
|
|
|
* @param $expected
|
|
|
|
|
* @throws \Wikia\PortableInfobox\Parser\XmlMarkupParseErrorException
|
2015-07-22 11:04:41 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testVideo( $markup, $params, $expected ) {
|
|
|
|
|
$fileMock = new FileMock();
|
|
|
|
|
$xmlObj = Wikia\PortableInfobox\Parser\XmlParser::parseXmlString( $markup );
|
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
|
$mock = $this->getMock(NodeImage::class, [ 'getFilefromTitle' ], [ $xmlObj, $params ]);
|
|
|
|
|
$mock->expects( $this->any( ))
|
|
|
|
|
->method( 'getFilefromTitle' )
|
|
|
|
|
->willReturn( $fileMock );
|
2015-07-22 13:15:08 +00:00
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
|
$this->assertEquals( $expected, $mock->getData() );
|
2015-07-22 11:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 18:07:51 +00:00
|
|
|
|
public function videoProvider() {
|
2015-07-22 11:04:41 +00:00
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'<image source="img" />',
|
|
|
|
|
[ 'img' => 'test.jpg' ],
|
|
|
|
|
[
|
2015-10-16 01:15:52 +00:00
|
|
|
|
[
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.jpg',
|
|
|
|
|
'key' => 'Test.jpg',
|
2018-08-08 09:42:22 +00:00
|
|
|
|
'alt' => 'Test.jpg',
|
2015-10-16 01:15:52 +00:00
|
|
|
|
'caption' => null,
|
2018-08-08 09:42:22 +00:00
|
|
|
|
'isVideo' => true
|
2015-10-16 01:15:52 +00:00
|
|
|
|
]
|
2015-07-22 11:04:41 +00:00
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FileMock {
|
|
|
|
|
public function getMediaType() {
|
|
|
|
|
return "VIDEO";
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 13:15:08 +00:00
|
|
|
|
public function getUrl() {
|
2018-08-08 09:42:22 +00:00
|
|
|
|
return 'http://test.url';
|
2015-07-22 11:04:41 +00:00
|
|
|
|
}
|
2018-08-08 09:42:22 +00:00
|
|
|
|
}
|
2015-09-09 11:23:34 +00:00
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
|
class GalleryMock {
|
|
|
|
|
private $images;
|
|
|
|
|
public function __construct( Array $images = [] ) {
|
|
|
|
|
$this->images = $images;
|
2015-09-09 11:23:34 +00:00
|
|
|
|
}
|
2015-09-07 16:21:17 +00:00
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
|
public function getImages() {
|
|
|
|
|
return $this->images;
|
2015-09-07 16:21:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|