2 class GIFHandlerTest
extends MediaWikiTestCase
{
4 /** @var FSFileBackend */
13 protected function setUp() {
16 $this->filePath
= __DIR__
. '/../../data/media';
17 $this->backend
= new FSFileBackend( array(
18 'name' => 'localtesting',
19 'wikiId' => wfWikiId(),
20 'containerPaths' => array( 'data' => $this->filePath
)
22 $this->repo
= new FSRepo( array(
24 'url' => 'http://localhost/thumbtest',
25 'backend' => $this->backend
27 $this->handler
= new GIFHandler();
31 * @covers GIFHandler::getMetadata
33 public function testInvalidFile() {
34 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
35 $this->assertEquals( GIFHandler
::BROKEN_FILE
, $res );
39 * @param string $filename Basename of the file to check
40 * @param bool $expected Expected result.
41 * @dataProvider provideIsAnimated
42 * @covers GIFHandler::isAnimatedImage
44 public function testIsAnimanted( $filename, $expected ) {
45 $file = $this->dataFile( $filename, 'image/gif' );
46 $actual = $this->handler
->isAnimatedImage( $file );
47 $this->assertEquals( $expected, $actual );
50 public static function provideIsAnimated() {
52 array( 'animated.gif', true ),
53 array( 'nonanimated.gif', false ),
58 * @param string $filename
59 * @param int $expected Total image area
60 * @dataProvider provideGetImageArea
61 * @covers GIFHandler::getImageArea
63 public function testGetImageArea( $filename, $expected ) {
64 $file = $this->dataFile( $filename, 'image/gif' );
65 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
66 $this->assertEquals( $expected, $actual );
69 public static function provideGetImageArea() {
71 array( 'animated.gif', 5400 ),
72 array( 'nonanimated.gif', 1350 ),
77 * @param string $metadata Serialized metadata
78 * @param int $expected One of the class constants of GIFHandler
79 * @dataProvider provideIsMetadataValid
80 * @covers GIFHandler::isMetadataValid
82 public function testIsMetadataValid( $metadata, $expected ) {
83 $actual = $this->handler
->isMetadataValid( null, $metadata );
84 $this->assertEquals( $expected, $actual );
87 public static function provideIsMetadataValid() {
89 array( GIFHandler
::BROKEN_FILE
, GIFHandler
::METADATA_GOOD
),
90 array( '', GIFHandler
::METADATA_BAD
),
91 array( null, GIFHandler
::METADATA_BAD
),
92 array( 'Something invalid!', GIFHandler
::METADATA_BAD
),
93 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
94 array( 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}', GIFHandler
::METADATA_GOOD
),
95 // @codingStandardsIgnoreEnd
100 * @param string $filename
101 * @param string $expected Serialized array
102 * @dataProvider provideGetMetadata
103 * @covers GIFHandler::getMetadata
105 public function testGetMetadata( $filename, $expected ) {
106 $file = $this->dataFile( $filename, 'image/gif' );
107 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
108 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
111 public static function provideGetMetadata() {
113 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
114 array( 'nonanimated.gif', 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
115 array( 'animated-xmp.gif', 'a:4:{s:10:"frameCount";i:4;s:6:"looped";b:1;s:8:"duration";d:2.399999999999999911182158029987476766109466552734375;s:8:"metadata";a:5:{s:6:"Artist";s:7:"Bawolff";s:16:"ImageDescription";a:2:{s:9:"x-default";s:18:"A file to test GIF";s:5:"_type";s:4:"lang";}s:15:"SublocationDest";s:13:"The interwebs";s:14:"GIFFileComment";a:1:{i:0;s:16:"GIƒ·test·file";}s:15:"_MW_GIF_VERSION";i:1;}}' ),
116 // @codingStandardsIgnoreEnd
121 * @param string $filename
122 * @param string $expected Serialized array
123 * @dataProvider provideGetIndependentMetaArray
124 * @covers GIFHandler::getCommonMetaArray
126 public function testGetIndependentMetaArray( $filename, $expected ) {
127 $file = $this->dataFile( $filename, 'image/gif' );
128 $actual = $this->handler
->getCommonMetaArray( $file );
129 $this->assertEquals( $expected, $actual );
132 public function provideGetIndependentMetaArray() {
134 array( 'nonanimated.gif', array(
135 'GIFFileComment' => array(
136 'GIF test file ⁕ Created with GIMP',
139 array( 'animated-xmp.gif',
141 'Artist' => 'Bawolff',
142 'ImageDescription' => array(
143 'x-default' => 'A file to test GIF',
146 'SublocationDest' => 'The interwebs',
156 private function dataFile( $name, $type ) {
157 return new UnregisteredLocalFile( false, $this->repo
,
158 "mwstore://localtesting/data/$name", $type );