2015-06-09 12:31:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class PortableInfoboxDataServiceTest extends PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
$this->setupFile = dirname( __FILE__ ) . '/../PortableInfobox.setup.php';
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getInfoboxData() {
|
|
|
|
$data =
|
|
|
|
[
|
|
|
|
[ // INFOBOX 1
|
2015-06-22 16:29:27 +00:00
|
|
|
'data' => [
|
|
|
|
[
|
|
|
|
"type" => "data",
|
|
|
|
"data" => [
|
|
|
|
"value" => "AAAA",
|
|
|
|
"label" => "BBBB"
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"type" => "image",
|
|
|
|
"data" => [
|
|
|
|
"key" => "Test.jpg",
|
|
|
|
"alt" => null,
|
|
|
|
"caption" => null,
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"type" => "image",
|
|
|
|
"data" => [
|
|
|
|
"key" => "Test2.jpg",
|
|
|
|
"alt" => null,
|
|
|
|
"caption" => null
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2015-06-09 12:31:04 +00:00
|
|
|
],
|
|
|
|
[ // INFOBOX 2
|
2015-06-22 16:29:27 +00:00
|
|
|
'data' => [
|
|
|
|
[
|
|
|
|
"type" => "image",
|
|
|
|
"data" => [
|
|
|
|
"key" => "Test2.jpg",
|
|
|
|
"alt" => null,
|
|
|
|
"caption" => null
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2015-06-09 12:31:04 +00:00
|
|
|
]
|
|
|
|
];
|
2015-06-22 16:29:27 +00:00
|
|
|
|
2015-06-09 12:31:04 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testImageListRemoveDuplicates() {
|
2015-06-22 16:29:27 +00:00
|
|
|
$mock = $this->getMockBuilder( 'PortableInfoboxDataService' )
|
2015-06-23 08:41:15 +00:00
|
|
|
->disableOriginalConstructor()
|
2015-06-22 16:29:27 +00:00
|
|
|
->setMethods( [ 'getData' ] )
|
|
|
|
->getMock();
|
|
|
|
$mock->expects( $this->any() )->method( 'getData' )->will( $this->returnValue( $this->getInfoboxData() ) );
|
|
|
|
|
|
|
|
$images = $mock->getImages();
|
2015-06-09 14:16:48 +00:00
|
|
|
$this->assertTrue( count( $images ) === 2 );
|
2015-06-09 12:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 08:41:15 +00:00
|
|
|
public function testImageListFetchImages() {
|
|
|
|
$mock = $this->getMockBuilder( 'PortableInfoboxDataService' )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods( [ 'getData' ] )
|
|
|
|
->getMock();
|
|
|
|
$mock->expects( $this->any() )->method( 'getData' )->will( $this->returnValue( $this->getInfoboxData() ) );
|
2015-06-22 16:29:27 +00:00
|
|
|
|
2015-06-23 08:41:15 +00:00
|
|
|
$images = $mock->getImages();
|
|
|
|
$this->assertTrue( in_array( "Test.jpg", $images ), "Test.jpg should be in images array" );
|
|
|
|
$this->assertTrue( in_array( "Test2.jpg", $images ), "Test2.jpg should be in images array" );
|
|
|
|
}
|
2015-06-09 12:31:04 +00:00
|
|
|
|
2015-07-01 13:17:52 +00:00
|
|
|
public function testTitleNullConstructor() {
|
|
|
|
$service = PortableInfoboxDataService::newFromTitle(null);
|
|
|
|
$result = $service->getData();
|
|
|
|
$this->assertEquals( [], $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testConstructor() {
|
|
|
|
$service = PortableInfoboxDataService::newFromPageID(null);
|
|
|
|
$result = $service->getData();
|
|
|
|
$this->assertEquals( [], $result );
|
|
|
|
}
|
|
|
|
|
2015-06-09 12:31:04 +00:00
|
|
|
}
|