2015-06-11 12:51:54 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2018-08-09 09:49:10 +00:00
|
|
|
|
use PortableInfobox\Helpers\PortableInfoboxDataBag;
|
2018-08-22 14:22:30 +00:00
|
|
|
|
use PortableInfobox\Helpers\PortableInfoboxImagesHelper;
|
|
|
|
|
use PortableInfobox\Parser\Nodes\NodeFactory;
|
2018-08-12 15:50:16 +00:00
|
|
|
|
use PortableInfobox\Parser\Nodes\NodeMedia;
|
2017-01-25 11:18:20 +00:00
|
|
|
|
|
2018-08-08 09:42:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* @group PortableInfobox
|
2018-08-12 15:50:16 +00:00
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia
|
2018-08-08 09:42:22 +00:00
|
|
|
|
*/
|
2018-08-12 15:50:16 +00:00
|
|
|
|
class NodeMediaTest extends MediaWikiTestCase {
|
2018-08-08 09:42:22 +00:00
|
|
|
|
|
2015-10-20 22:42:36 +00:00
|
|
|
|
/**
|
2018-08-12 15:50:16 +00:00
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getGalleryData
|
2018-08-13 14:31:50 +00:00
|
|
|
|
* @covers PortableInfobox\Helpers\PortableInfoboxDataBag
|
2017-01-25 11:18:20 +00:00
|
|
|
|
* @dataProvider galleryDataProvider
|
|
|
|
|
* @param $marker
|
|
|
|
|
* @param $expected
|
2015-10-20 22:42:36 +00:00
|
|
|
|
*/
|
2018-08-13 14:31:50 +00:00
|
|
|
|
public function testGalleryData( $marker, $gallery, $expected ) {
|
|
|
|
|
PortableInfoboxDataBag::getInstance()->setGallery( $marker, $gallery );
|
2018-08-12 15:50:16 +00:00
|
|
|
|
$this->assertEquals( $expected, NodeMedia::getGalleryData( $marker ) );
|
2017-01-25 11:18:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function galleryDataProvider() {
|
|
|
|
|
$markers = [
|
|
|
|
|
"'\"`UNIQabcd-gAlLeRy-1-QINU`\"'",
|
|
|
|
|
"'\"`UNIQabcd-gAlLeRy-2-QINU`\"'",
|
|
|
|
|
"'\"`UNIQabcd-gAlLeRy-3-QINU`\"'"
|
|
|
|
|
];
|
2018-08-13 14:31:50 +00:00
|
|
|
|
$galleries = [
|
2018-08-16 09:25:53 +00:00
|
|
|
|
new GalleryMock( [
|
2018-08-13 14:31:50 +00:00
|
|
|
|
[
|
|
|
|
|
'image0_name.jpg',
|
|
|
|
|
'image0_caption'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'image01_name.jpg',
|
|
|
|
|
'image01_caption'
|
|
|
|
|
],
|
2018-08-16 09:25:53 +00:00
|
|
|
|
] ),
|
|
|
|
|
new GalleryMock( [
|
2018-08-13 14:31:50 +00:00
|
|
|
|
[
|
|
|
|
|
'image1_name.jpg',
|
|
|
|
|
'image1_caption'
|
|
|
|
|
]
|
2018-08-16 09:25:53 +00:00
|
|
|
|
] ),
|
2018-08-13 14:31:50 +00:00
|
|
|
|
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],
|
2018-08-13 14:31:50 +00:00
|
|
|
|
'gallery' => $galleries[0],
|
2017-01-25 11:18:20 +00:00
|
|
|
|
'expected' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => 'image0_caption',
|
|
|
|
|
'title' => 'image0_name.jpg',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label' => 'image01_caption',
|
|
|
|
|
'title' => 'image01_name.jpg',
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'marker' => $markers[1],
|
2018-08-13 14:31:50 +00:00
|
|
|
|
'gallery' => $galleries[1],
|
2017-01-25 11:18:20 +00:00
|
|
|
|
'expected' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => 'image1_caption',
|
|
|
|
|
'title' => 'image1_name.jpg',
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'marker' => $markers[2],
|
2018-08-13 14:31:50 +00:00
|
|
|
|
'gallery' => $galleries[2],
|
2017-01-25 11:18:20 +00:00
|
|
|
|
'expected' => []
|
|
|
|
|
],
|
2017-01-02 13:31:45 +00:00
|
|
|
|
];
|
2015-10-20 22:42:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-12 15:50:16 +00:00
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getTabberData
|
2015-10-20 22:42:36 +00:00
|
|
|
|
*/
|
|
|
|
|
public function testTabberData() {
|
2018-10-02 07:41:19 +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
|
|
|
|
]
|
|
|
|
|
];
|
2018-08-12 15:50:16 +00:00
|
|
|
|
$this->assertEquals( $expected, NodeMedia::getTabberData( $input ) );
|
2015-10-20 22:42:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-12 15:50:16 +00:00
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia::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 ) {
|
2018-10-02 07:41:19 +00:00
|
|
|
|
$this->assertEquals( $expected, NodeMedia::getMarkers( $value, $ext ) );
|
2015-10-20 22:42:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-10-02 07:41:19 +00:00
|
|
|
|
"\x7f'\"`UNIQ--tAbBeR-12345678-QINU`\"'\x7f" .
|
|
|
|
|
"<center>\x7f'\"`UNIQ--gAlLeRy-12345678-QINU`\"'\x7f</center>" .
|
|
|
|
|
"\x7f'\"`UNIQ--gAlLeRy-87654321-QINU`\"'\x7f",
|
2018-08-08 09:42:22 +00:00
|
|
|
|
[ "\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",
|
2018-08-16 09:25:53 +00:00
|
|
|
|
[]
|
2015-10-20 22:42:36 +00:00
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-11 12:51:54 +00:00
|
|
|
|
/**
|
2018-08-12 15:50:16 +00:00
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getData
|
2015-06-11 12:51:54 +00:00
|
|
|
|
* @dataProvider dataProvider
|
|
|
|
|
*
|
|
|
|
|
* @param $markup
|
|
|
|
|
* @param $params
|
2018-08-22 14:22:30 +00:00
|
|
|
|
* @param $mediaType
|
2015-06-11 12:51:54 +00:00
|
|
|
|
* @param $expected
|
|
|
|
|
*/
|
2018-08-22 14:22:30 +00:00
|
|
|
|
public function testData( $markup, $params, $mediaType, $expected ) {
|
|
|
|
|
$fileMock = is_null( $mediaType ) ? null : new FileMock( $mediaType );
|
|
|
|
|
$node = NodeFactory::newFromXML( $markup, $params );
|
|
|
|
|
|
2021-09-11 23:07:07 +00:00
|
|
|
|
$helper = $this->getMockBuilder( PortableInfoboxImagesHelper::class )
|
|
|
|
|
->setMethods( [ 'getFile', 'extendImageData' ] )
|
|
|
|
|
->getMock();
|
2018-08-22 14:22:30 +00:00
|
|
|
|
$helper->expects( $this->any() )
|
|
|
|
|
->method( 'getFile' )
|
|
|
|
|
->willReturn( $fileMock );
|
|
|
|
|
$helper->expects( $this->any() )
|
|
|
|
|
->method( 'extendImageData' )
|
|
|
|
|
->willReturn( [] );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
2018-08-22 14:22:30 +00:00
|
|
|
|
$reflection = new ReflectionClass( $node );
|
|
|
|
|
$reflectionProperty = $reflection->getProperty( 'helper' );
|
|
|
|
|
$reflectionProperty->setAccessible( true );
|
|
|
|
|
$reflectionProperty->setValue( $node, $helper );
|
2018-08-12 15:50:16 +00:00
|
|
|
|
|
2018-08-22 14:22:30 +00:00
|
|
|
|
$this->assertEquals( $expected, $node->getData() );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"></media>',
|
2018-08-16 09:25:53 +00:00
|
|
|
|
[],
|
2018-08-22 14:22:30 +00:00
|
|
|
|
null,
|
2018-08-16 09:25:53 +00:00
|
|
|
|
[ [] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"></media>',
|
2015-10-20 21:28:27 +00:00
|
|
|
|
[ 'img' => 'test.jpg' ],
|
2018-08-22 14:22:30 +00:00
|
|
|
|
MEDIATYPE_BITMAP,
|
|
|
|
|
[ [
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.jpg',
|
|
|
|
|
'alt' => 'Test.jpg',
|
|
|
|
|
'caption' => null,
|
|
|
|
|
'isImage' => true,
|
|
|
|
|
'isVideo' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
|
'isAudio' => false,
|
2019-02-02 22:34:48 +00:00
|
|
|
|
'source' => 'img',
|
|
|
|
|
'item-name' => null
|
2018-08-22 14:22:30 +00:00
|
|
|
|
] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"><alt><default>test alt</default></alt></media>',
|
2015-10-20 21:28:27 +00:00
|
|
|
|
[ 'img' => 'test.jpg' ],
|
2018-08-22 14:22:30 +00:00
|
|
|
|
MEDIATYPE_BITMAP,
|
|
|
|
|
[ [
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.jpg',
|
|
|
|
|
'alt' => 'test alt',
|
|
|
|
|
'caption' => null,
|
|
|
|
|
'isImage' => true,
|
|
|
|
|
'isVideo' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
|
'isAudio' => false,
|
2019-02-02 22:34:48 +00:00
|
|
|
|
'source' => 'img',
|
|
|
|
|
'item-name' => null
|
2018-08-22 14:22:30 +00:00
|
|
|
|
] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"><alt source="alt source"><default>test alt</default></alt></media>',
|
2015-10-20 21:28:27 +00:00
|
|
|
|
[ 'img' => 'test.jpg', 'alt source' => 2 ],
|
2018-08-22 14:22:30 +00:00
|
|
|
|
MEDIATYPE_BITMAP,
|
|
|
|
|
[ [
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.jpg',
|
|
|
|
|
'alt' => 2,
|
|
|
|
|
'caption' => null,
|
|
|
|
|
'isImage' => true,
|
|
|
|
|
'isVideo' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
|
'isAudio' => false,
|
2019-02-02 22:34:48 +00:00
|
|
|
|
'source' => 'img',
|
|
|
|
|
'item-name' => null
|
2018-08-22 14:22:30 +00:00
|
|
|
|
] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"><alt><default>test alt</default></alt><caption source="img"/></media>',
|
2015-10-20 21:28:27 +00:00
|
|
|
|
[ 'img' => 'test.jpg' ],
|
2018-08-22 14:22:30 +00:00
|
|
|
|
MEDIATYPE_BITMAP,
|
|
|
|
|
[ [
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.jpg',
|
|
|
|
|
'alt' => 'test alt',
|
|
|
|
|
'caption' => 'test.jpg',
|
|
|
|
|
'isImage' => true,
|
|
|
|
|
'isVideo' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
|
'isAudio' => false,
|
2019-02-02 22:34:48 +00:00
|
|
|
|
'source' => 'img',
|
|
|
|
|
'item-name' => null
|
2018-08-22 14:22:30 +00:00
|
|
|
|
] ]
|
|
|
|
|
],
|
2019-02-03 16:49:06 +00:00
|
|
|
|
[
|
|
|
|
|
'<media source="img" name="img" />',
|
|
|
|
|
[ 'img' => 'test.jpg' ],
|
|
|
|
|
MEDIATYPE_BITMAP,
|
|
|
|
|
[ [
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.jpg',
|
|
|
|
|
'alt' => 'Test.jpg',
|
|
|
|
|
'caption' => null,
|
|
|
|
|
'isImage' => true,
|
|
|
|
|
'isVideo' => false,
|
|
|
|
|
'isAudio' => false,
|
|
|
|
|
'source' => 'img',
|
|
|
|
|
'item-name' => 'img'
|
|
|
|
|
] ]
|
|
|
|
|
],
|
2018-08-22 14:22:30 +00:00
|
|
|
|
[
|
|
|
|
|
'<media source="media" />',
|
|
|
|
|
[ 'media' => 'test.webm' ],
|
|
|
|
|
MEDIATYPE_VIDEO,
|
|
|
|
|
[ [
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.webm',
|
|
|
|
|
'alt' => 'Test.webm',
|
|
|
|
|
'caption' => null,
|
|
|
|
|
'isImage' => false,
|
|
|
|
|
'isVideo' => true,
|
2018-12-27 01:01:19 +00:00
|
|
|
|
'isAudio' => false,
|
2019-02-02 22:34:48 +00:00
|
|
|
|
'source' => 'media',
|
|
|
|
|
'item-name' => null
|
2018-08-22 14:22:30 +00:00
|
|
|
|
] ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<media source="media" video="false" />',
|
|
|
|
|
[ 'media' => 'test.webm' ],
|
|
|
|
|
MEDIATYPE_VIDEO,
|
|
|
|
|
[ [] ]
|
2015-10-20 21:28:27 +00:00
|
|
|
|
],
|
2018-08-22 14:22:30 +00:00
|
|
|
|
[
|
|
|
|
|
'<media source="media" />',
|
|
|
|
|
[ 'media' => 'test.ogg' ],
|
|
|
|
|
MEDIATYPE_AUDIO,
|
|
|
|
|
[ [
|
|
|
|
|
'url' => 'http://test.url',
|
|
|
|
|
'name' => 'Test.ogg',
|
|
|
|
|
'alt' => 'Test.ogg',
|
|
|
|
|
'caption' => null,
|
|
|
|
|
'isImage' => false,
|
|
|
|
|
'isVideo' => false,
|
2018-12-27 01:01:19 +00:00
|
|
|
|
'isAudio' => true,
|
2019-02-02 22:34:48 +00:00
|
|
|
|
'source' => 'media',
|
|
|
|
|
'item-name' => null
|
2018-08-22 14:22:30 +00:00
|
|
|
|
] ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<media source="media" audio="false" />',
|
|
|
|
|
[ 'media' => 'test.ogg' ],
|
|
|
|
|
MEDIATYPE_AUDIO,
|
|
|
|
|
[ [] ]
|
|
|
|
|
]
|
2015-06-11 12:51:54 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-12 15:50:16 +00:00
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia::isEmpty
|
2015-06-11 12:51:54 +00:00
|
|
|
|
* @dataProvider isEmptyProvider
|
|
|
|
|
*
|
|
|
|
|
* @param $markup
|
|
|
|
|
* @param $params
|
|
|
|
|
* @param $expected
|
|
|
|
|
*/
|
|
|
|
|
public function testIsEmpty( $markup, $params, $expected ) {
|
2018-08-22 14:22:30 +00:00
|
|
|
|
$node = NodeFactory::newFromXML( $markup, $params );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->isEmpty() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isEmptyProvider() {
|
|
|
|
|
return [
|
2018-08-16 09:25:53 +00:00
|
|
|
|
[ '<media></media>', [], true ],
|
2015-06-11 12:51:54 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-08-12 15:50:16 +00:00
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia::getSources
|
2016-12-14 12:54:53 +00:00
|
|
|
|
* @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 ) {
|
2018-08-22 14:22:30 +00:00
|
|
|
|
$node = NodeFactory::newFromXML( $markup, [] );
|
2015-06-11 12:51:54 +00:00
|
|
|
|
|
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
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"/>',
|
2015-10-20 21:30:07 +00:00
|
|
|
|
[ 'img' ]
|
|
|
|
|
],
|
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"><default>{{{img}}}</default><alt source="img" /></media>',
|
2015-10-20 21:30:07 +00:00
|
|
|
|
[ 'img' ]
|
|
|
|
|
],
|
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media source="img"><alt source="alt"/><caption source="cap"/></media>',
|
2015-10-20 21:30:07 +00:00
|
|
|
|
[ 'img', 'alt', 'cap' ]
|
|
|
|
|
],
|
|
|
|
|
[
|
2018-10-02 07:41:19 +00:00
|
|
|
|
'<media source="img">' .
|
|
|
|
|
'<alt source="alt"><default>{{{def}}}</default></alt><caption source="cap"/>' .
|
|
|
|
|
'</media>',
|
2015-10-20 21:30:07 +00:00
|
|
|
|
[ 'img', 'alt', 'def', 'cap' ] ],
|
|
|
|
|
[
|
2018-08-12 15:50:16 +00:00
|
|
|
|
'<media/>',
|
2018-08-16 09:25:53 +00:00
|
|
|
|
[]
|
2015-10-20 21:30:07 +00:00
|
|
|
|
],
|
2017-01-02 13:31:45 +00:00
|
|
|
|
[
|
2018-10-02 07:41:19 +00:00
|
|
|
|
'<image source="img">' .
|
|
|
|
|
'<caption source="cap"><format>Test {{{cap}}} and {{{fcap}}}</format></caption>' .
|
|
|
|
|
'</image>',
|
2017-01-02 13:31:45 +00:00
|
|
|
|
[ 'img', 'cap', 'fcap' ]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @dataProvider metadataProvider */
|
|
|
|
|
public function testMetadata( $markup, $expected ) {
|
2018-08-22 14:22:30 +00:00
|
|
|
|
$node = NodeFactory::newFromXML( $markup, [] );
|
2017-01-02 13:31:45 +00:00
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $node->getMetadata() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function metadataProvider() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
2018-10-02 07:41:19 +00:00
|
|
|
|
'<media source="img">' .
|
|
|
|
|
'<caption source="cap"><format>Test {{{cap}}} and {{{fcap}}}</format></caption>' .
|
|
|
|
|
'</media>',
|
|
|
|
|
[
|
|
|
|
|
'type' => 'media',
|
|
|
|
|
'sources' => [
|
|
|
|
|
'img' => [ 'label' => '', 'primary' => true ],
|
|
|
|
|
'cap' => [ 'label' => '' ],
|
|
|
|
|
'fcap' => [ 'label' => '' ]
|
|
|
|
|
]
|
|
|
|
|
]
|
2017-01-02 13:31:45 +00:00
|
|
|
|
]
|
2015-06-11 12:51:54 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
2015-07-22 11:04:41 +00:00
|
|
|
|
|
2018-08-13 14:31:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeMedia::isTypeAllowed
|
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeAudio
|
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeImage
|
|
|
|
|
* @covers PortableInfobox\Parser\Nodes\NodeVideo
|
|
|
|
|
* @dataProvider isTypeAllowedProvider
|
|
|
|
|
* @param $markup
|
|
|
|
|
* @param $expected
|
|
|
|
|
* @throws PortableInfobox\Parser\XmlMarkupParseErrorException
|
|
|
|
|
*/
|
|
|
|
|
public function testIsTypeAllowed( $markup, $expected ) {
|
|
|
|
|
$types = [ MEDIATYPE_BITMAP, MEDIATYPE_DRAWING, MEDIATYPE_VIDEO, MEDIATYPE_AUDIO, 'unknown' ];
|
|
|
|
|
|
|
|
|
|
$node = PortableInfobox\Parser\Nodes\NodeFactory::newFromXML( $markup, [] );
|
|
|
|
|
|
|
|
|
|
$reflection = new ReflectionClass( $node );
|
|
|
|
|
$reflection_method = $reflection->getMethod( 'isTypeAllowed' );
|
|
|
|
|
$reflection_method->setAccessible( true );
|
|
|
|
|
|
|
|
|
|
foreach ( $types as $i => $type ) {
|
|
|
|
|
$this->assertEquals( $expected[$i], $reflection_method->invoke( $node, $type ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isTypeAllowedProvider() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'<media />',
|
|
|
|
|
[ true, true, true, true, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<media image="false" />',
|
|
|
|
|
[ false, false, true, true, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<media video="false" />',
|
|
|
|
|
[ true, true, false, true, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<media audio="false" />',
|
|
|
|
|
[ true, true, true, false, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<media image="false" video="false" audio="false" />',
|
|
|
|
|
[ false, false, false, false, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<image />',
|
|
|
|
|
[ true, true, true, false, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<image video="false" />',
|
|
|
|
|
[ true, true, false, false, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<video />',
|
|
|
|
|
[ false, false, true, false, false ]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'<audio />',
|
|
|
|
|
[ false, false, false, true, false ]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
2015-07-22 11:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-22 14:22:30 +00:00
|
|
|
|
class FileMock {
|
|
|
|
|
protected $mediaType;
|
2018-08-12 15:50:16 +00:00
|
|
|
|
|
2018-08-22 14:22:30 +00:00
|
|
|
|
public function __construct( $mediaType ) {
|
|
|
|
|
$this->mediaType = $mediaType;
|
2018-08-12 15:50:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 11:04:41 +00:00
|
|
|
|
public function getMediaType() {
|
2018-08-22 14:22:30 +00:00
|
|
|
|
return $this->mediaType;
|
2015-07-22 11:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2018-08-12 15:50:16 +00:00
|
|
|
|
public function __construct( array $images = [] ) {
|
2018-08-08 09:42:22 +00:00
|
|
|
|
$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
|
|
|
|
}
|
|
|
|
|
}
|