2 class GIFHandlerTest
extends MediaWikiMediaTestCase
{
7 protected function setUp() {
10 $this->handler
= new GIFHandler();
14 * @covers GIFHandler::getMetadata
16 public function testInvalidFile() {
17 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
18 $this->assertEquals( GIFHandler
::BROKEN_FILE
, $res );
22 * @param string $filename Basename of the file to check
23 * @param bool $expected Expected result.
24 * @dataProvider provideIsAnimated
25 * @covers GIFHandler::isAnimatedImage
27 public function testIsAnimanted( $filename, $expected ) {
28 $file = $this->dataFile( $filename, 'image/gif' );
29 $actual = $this->handler
->isAnimatedImage( $file );
30 $this->assertEquals( $expected, $actual );
33 public static function provideIsAnimated() {
35 array( 'animated.gif', true ),
36 array( 'nonanimated.gif', false ),
41 * @param string $filename
42 * @param int $expected Total image area
43 * @dataProvider provideGetImageArea
44 * @covers GIFHandler::getImageArea
46 public function testGetImageArea( $filename, $expected ) {
47 $file = $this->dataFile( $filename, 'image/gif' );
48 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
49 $this->assertEquals( $expected, $actual );
52 public static function provideGetImageArea() {
54 array( 'animated.gif', 5400 ),
55 array( 'nonanimated.gif', 1350 ),
60 * @param string $metadata Serialized metadata
61 * @param int $expected One of the class constants of GIFHandler
62 * @dataProvider provideIsMetadataValid
63 * @covers GIFHandler::isMetadataValid
65 public function testIsMetadataValid( $metadata, $expected ) {
66 $actual = $this->handler
->isMetadataValid( null, $metadata );
67 $this->assertEquals( $expected, $actual );
70 public static function provideIsMetadataValid() {
72 array( GIFHandler
::BROKEN_FILE
, GIFHandler
::METADATA_GOOD
),
73 array( '', GIFHandler
::METADATA_BAD
),
74 array( null, GIFHandler
::METADATA_BAD
),
75 array( 'Something invalid!', GIFHandler
::METADATA_BAD
),
76 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
77 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
),
78 // @codingStandardsIgnoreEnd
83 * @param string $filename
84 * @param string $expected Serialized array
85 * @dataProvider provideGetMetadata
86 * @covers GIFHandler::getMetadata
88 public function testGetMetadata( $filename, $expected ) {
89 $file = $this->dataFile( $filename, 'image/gif' );
90 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
91 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
94 public static function provideGetMetadata() {
96 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
97 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;}}' ),
98 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;}}' ),
99 // @codingStandardsIgnoreEnd
104 * @param string $filename
105 * @param string $expected Serialized array
106 * @dataProvider provideGetIndependentMetaArray
107 * @covers GIFHandler::getCommonMetaArray
109 public function testGetIndependentMetaArray( $filename, $expected ) {
110 $file = $this->dataFile( $filename, 'image/gif' );
111 $actual = $this->handler
->getCommonMetaArray( $file );
112 $this->assertEquals( $expected, $actual );
115 public function provideGetIndependentMetaArray() {
117 array( 'nonanimated.gif', array(
118 'GIFFileComment' => array(
119 'GIF test file ⁕ Created with GIMP',
122 array( 'animated-xmp.gif',
124 'Artist' => 'Bawolff',
125 'ImageDescription' => array(
126 'x-default' => 'A file to test GIF',
129 'SublocationDest' => 'The interwebs',