Merge "DBConnectionError: Expand {{SITENAME}} in pagetitle with Message::text()"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / GIFTest.php
1 <?php
2 class GIFHandlerTest extends MediaWikiMediaTestCase {
3
4 /** @var GIFHandler */
5 protected $handler;
6
7 protected function setUp() {
8 parent::setUp();
9
10 $this->handler = new GIFHandler();
11 }
12
13 /**
14 * @covers GIFHandler::getMetadata
15 */
16 public function testInvalidFile() {
17 $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
18 $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
19 }
20
21 /**
22 * @param string $filename Basename of the file to check
23 * @param bool $expected Expected result.
24 * @dataProvider provideIsAnimated
25 * @covers GIFHandler::isAnimatedImage
26 */
27 public function testIsAnimanted( $filename, $expected ) {
28 $file = $this->dataFile( $filename, 'image/gif' );
29 $actual = $this->handler->isAnimatedImage( $file );
30 $this->assertEquals( $expected, $actual );
31 }
32
33 public static function provideIsAnimated() {
34 return array(
35 array( 'animated.gif', true ),
36 array( 'nonanimated.gif', false ),
37 );
38 }
39
40 /**
41 * @param string $filename
42 * @param int $expected Total image area
43 * @dataProvider provideGetImageArea
44 * @covers GIFHandler::getImageArea
45 */
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 );
50 }
51
52 public static function provideGetImageArea() {
53 return array(
54 array( 'animated.gif', 5400 ),
55 array( 'nonanimated.gif', 1350 ),
56 );
57 }
58
59 /**
60 * @param string $metadata Serialized metadata
61 * @param int $expected One of the class constants of GIFHandler
62 * @dataProvider provideIsMetadataValid
63 * @covers GIFHandler::isMetadataValid
64 */
65 public function testIsMetadataValid( $metadata, $expected ) {
66 $actual = $this->handler->isMetadataValid( null, $metadata );
67 $this->assertEquals( $expected, $actual );
68 }
69
70 public static function provideIsMetadataValid() {
71 return array(
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
79 );
80 }
81
82 /**
83 * @param string $filename
84 * @param string $expected Serialized array
85 * @dataProvider provideGetMetadata
86 * @covers GIFHandler::getMetadata
87 */
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 ) );
92 }
93
94 public static function provideGetMetadata() {
95 return array(
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
100 );
101 }
102
103 /**
104 * @param string $filename
105 * @param string $expected Serialized array
106 * @dataProvider provideGetIndependentMetaArray
107 * @covers GIFHandler::getCommonMetaArray
108 */
109 public function testGetIndependentMetaArray( $filename, $expected ) {
110 $file = $this->dataFile( $filename, 'image/gif' );
111 $actual = $this->handler->getCommonMetaArray( $file );
112 $this->assertEquals( $expected, $actual );
113 }
114
115 public function provideGetIndependentMetaArray() {
116 return array(
117 array( 'nonanimated.gif', array(
118 'GIFFileComment' => array(
119 'GIF test file ⁕ Created with GIMP',
120 ),
121 ) ),
122 array( 'animated-xmp.gif',
123 array(
124 'Artist' => 'Bawolff',
125 'ImageDescription' => array(
126 'x-default' => 'A file to test GIF',
127 '_type' => 'lang',
128 ),
129 'SublocationDest' => 'The interwebs',
130 'GIFFileComment' =>
131 array(
132 'GIƒ·test·file',
133 ),
134 )
135 ),
136 );
137 }
138 }