(follow-up r99910) Make $wgEnableAutoRotation work...
[lhc/web/wiklou.git] / tests / phpunit / includes / media / GIFTest.php
1 <?php
2 class GIFHandlerTest extends MediaWikiTestCase {
3
4 public function setUp() {
5 $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
6 $this->handler = new GIFHandler();
7 }
8
9 public function testInvalidFile() {
10 $res = $this->handler->getMetadata( null, $this->filePath . 'README' );
11 $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
12 }
13 /**
14 * @param $filename String basename of the file to check
15 * @param $expected boolean Expected result.
16 * @dataProvider dataIsAnimated
17 */
18 public function testIsAnimanted( $filename, $expected ) {
19 $file = UnregisteredLocalFile::newFromPath( $this->filePath . $filename,
20 'image/gif' );
21 $actual = $this->handler->isAnimatedImage( $file );
22 $this->assertEquals( $expected, $actual );
23 }
24 public function dataIsAnimated() {
25 return array(
26 array( 'animated.gif', true ),
27 array( 'nonanimated.gif', false ),
28 );
29 }
30
31 /**
32 * @param $filename String
33 * @param $expected Integer Total image area
34 * @dataProvider dataGetImageArea
35 */
36 public function testGetImageArea( $filename, $expected ) {
37 $file = UnregisteredLocalFile::newFromPath( $this->filePath . $filename,
38 'image/gif' );
39 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
40 $this->assertEquals( $expected, $actual );
41 }
42 public function dataGetImageArea() {
43 return array(
44 array( 'animated.gif', 5400 ),
45 array( 'nonanimated.gif', 1350 ),
46 );
47 }
48
49 /**
50 * @param $metadata String Serialized metadata
51 * @param $expected Integer One of the class constants of GIFHandler
52 * @dataProvider dataIsMetadataValid
53 */
54 public function testIsMetadataValid( $metadata, $expected ) {
55 $actual = $this->handler->isMetadataValid( null, $metadata );
56 $this->assertEquals( $expected, $actual );
57 }
58 public function dataIsMetadataValid() {
59 return array(
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 ),
65 );
66 }
67
68 /**
69 * @param $filename String
70 * @param $expected String Serialized array
71 * @dataProvider dataGetMetadata
72 */
73 public function testGetMetadata( $filename, $expected ) {
74 $file = UnregisteredLocalFile::newFromPath( $this->filePath . $filename,
75 'image/gif' );
76 $actual = $this->handler->getMetadata( $file, $this->filePath . $filename );
77 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
78 }
79 public function dataGetMetadata() {
80 return array(
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;}}' ),
83 );
84 }
85 }