Revert "Revert "Show a "(blocked)" hint on Special:ListUsers/ActiveUsers""
[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 = __DIR__ . '/../../data/media';
6 $this->backend = new FSFileBackend( array(
7 'name' => 'localtesting',
8 'lockManager' => 'nullLockManager',
9 'containerPaths' => array( 'data' => $this->filePath )
10 ) );
11 $this->repo = new FSRepo( array(
12 'name' => 'temp',
13 'url' => 'http://localhost/thumbtest',
14 'backend' => $this->backend
15 ) );
16 $this->handler = new GIFHandler();
17 }
18
19 public function testInvalidFile() {
20 $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
21 $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
22 }
23 /**
24 * @param $filename String basename of the file to check
25 * @param $expected boolean Expected result.
26 * @dataProvider dataIsAnimated
27 */
28 public function testIsAnimanted( $filename, $expected ) {
29 $file = $this->dataFile( $filename, 'image/gif' );
30 $actual = $this->handler->isAnimatedImage( $file );
31 $this->assertEquals( $expected, $actual );
32 }
33 public function dataIsAnimated() {
34 return array(
35 array( 'animated.gif', true ),
36 array( 'nonanimated.gif', false ),
37 );
38 }
39
40 /**
41 * @param $filename String
42 * @param $expected Integer Total image area
43 * @dataProvider dataGetImageArea
44 */
45 public function testGetImageArea( $filename, $expected ) {
46 $file = $this->dataFile( $filename, 'image/gif' );
47 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
48 $this->assertEquals( $expected, $actual );
49 }
50 public function dataGetImageArea() {
51 return array(
52 array( 'animated.gif', 5400 ),
53 array( 'nonanimated.gif', 1350 ),
54 );
55 }
56
57 /**
58 * @param $metadata String Serialized metadata
59 * @param $expected Integer One of the class constants of GIFHandler
60 * @dataProvider dataIsMetadataValid
61 */
62 public function testIsMetadataValid( $metadata, $expected ) {
63 $actual = $this->handler->isMetadataValid( null, $metadata );
64 $this->assertEquals( $expected, $actual );
65 }
66 public function dataIsMetadataValid() {
67 return array(
68 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ),
69 array( '', GIFHandler::METADATA_BAD ),
70 array( null, GIFHandler::METADATA_BAD ),
71 array( 'Something invalid!', GIFHandler::METADATA_BAD ),
72 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 ),
73 );
74 }
75
76 /**
77 * @param $filename String
78 * @param $expected String Serialized array
79 * @dataProvider dataGetMetadata
80 */
81 public function testGetMetadata( $filename, $expected ) {
82 $file = $this->dataFile( $filename, 'image/gif' );
83 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
84 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
85 }
86
87 public function dataGetMetadata() {
88 return array(
89 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;}}' ),
90 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;}}' ),
91 );
92 }
93
94 private function dataFile( $name, $type ) {
95 return new UnregisteredLocalFile( false, $this->repo,
96 "mwstore://localtesting/data/$name", $type );
97 }
98 }