2 class GIFHandlerTest
extends MediaWikiTestCase
{
4 public function setUp() {
5 $this->filePath
= dirname( __FILE__
) . '/../../data/media/';
6 $this->handler
= new GIFHandler();
9 public function testInvalidFile() {
10 $res = $this->handler
->getMetadata( null, $this->filePath
. 'README' );
11 $this->assertEquals( GIFHandler
::BROKEN_FILE
, $res );
14 * @param $filename String basename of the file to check
15 * @param $expected boolean Expected result.
16 * @dataProvider dataIsAnimated
18 public function testIsAnimanted( $filename, $expected ) {
19 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. $filename,
21 $actual = $this->handler
->isAnimatedImage( $file );
22 $this->assertEquals( $expected, $actual );
24 public function dataIsAnimated() {
26 array( 'animated.gif', true ),
27 array( 'nonanimated.gif', false ),
32 * @param $filename String
33 * @param $expected Integer Total image area
34 * @dataProvider dataGetImageArea
36 public function testGetImageArea( $filename, $expected ) {
37 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. $filename,
39 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
40 $this->assertEquals( $expected, $actual );
42 public function dataGetImageArea() {
44 array( 'animated.gif', 5400 ),
45 array( 'nonanimated.gif', 1350 ),
50 * @param $metadata String Serialized metadata
51 * @param $expected Integer One of the class constants of GIFHandler
52 * @dataProvider dataIsMetadataValid
54 public function testIsMetadataValid( $metadata, $expected ) {
55 $actual = $this->handler
->isMetadataValid( null, $metadata );
56 $this->assertEquals( $expected, $actual );
58 public function dataIsMetadataValid() {
60 array( GIFHandler
::BROKEN_FILE
, GIFHandler
::METADATA_GOOD
),
61 array( '', GIFHandler
::METADATA_BAD
),
62 array( null, GIFHandler
::METADATA_BAD
),
63 array( 'Something invalid!', GIFHandler
::METADATA_BAD
),
64 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
),
69 * @param $filename String
70 * @param $expected String Serialized array
71 * @dataProvider dataGetMetadata
73 public function testGetMetadata( $filename, $expected ) {
74 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. $filename,
76 $actual = $this->handler
->getMetadata( $file, $this->filePath
. $filename );
77 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
79 public function dataGetMetadata() {
81 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;}}' ),
82 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;}}' ),