Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / media / GIFTest.php
blob7a7ed217e81f3f2077ebe93d266b175bb57227b7
1 <?php
2 class GIFHandlerTest extends MediaWikiTestCase {
4 /** @var FSFileBackend */
5 protected $backend;
6 /** @var GIFHandler */
7 protected $handler;
8 /** @var FSRepo */
9 protected $repo;
10 /** @var string */
11 protected $filePath;
13 protected function setUp() {
14 parent::setUp();
16 $this->filePath = __DIR__ . '/../../data/media';
17 $this->backend = new FSFileBackend( array(
18 'name' => 'localtesting',
19 'wikiId' => wfWikiId(),
20 'containerPaths' => array( 'data' => $this->filePath )
21 ) );
22 $this->repo = new FSRepo( array(
23 'name' => 'temp',
24 'url' => 'http://localhost/thumbtest',
25 'backend' => $this->backend
26 ) );
27 $this->handler = new GIFHandler();
30 /**
31 * @covers GIFHandler::getMetadata
33 public function testInvalidFile() {
34 $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
35 $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
38 /**
39 * @param string $filename Basename of the file to check
40 * @param bool $expected Expected result.
41 * @dataProvider provideIsAnimated
42 * @covers GIFHandler::isAnimatedImage
44 public function testIsAnimanted( $filename, $expected ) {
45 $file = $this->dataFile( $filename, 'image/gif' );
46 $actual = $this->handler->isAnimatedImage( $file );
47 $this->assertEquals( $expected, $actual );
50 public static function provideIsAnimated() {
51 return array(
52 array( 'animated.gif', true ),
53 array( 'nonanimated.gif', false ),
57 /**
58 * @param string $filename
59 * @param int $expected Total image area
60 * @dataProvider provideGetImageArea
61 * @covers GIFHandler::getImageArea
63 public function testGetImageArea( $filename, $expected ) {
64 $file = $this->dataFile( $filename, 'image/gif' );
65 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
66 $this->assertEquals( $expected, $actual );
69 public static function provideGetImageArea() {
70 return array(
71 array( 'animated.gif', 5400 ),
72 array( 'nonanimated.gif', 1350 ),
76 /**
77 * @param string $metadata Serialized metadata
78 * @param int $expected One of the class constants of GIFHandler
79 * @dataProvider provideIsMetadataValid
80 * @covers GIFHandler::isMetadataValid
82 public function testIsMetadataValid( $metadata, $expected ) {
83 $actual = $this->handler->isMetadataValid( null, $metadata );
84 $this->assertEquals( $expected, $actual );
87 public static function provideIsMetadataValid() {
88 return array(
89 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ),
90 array( '', GIFHandler::METADATA_BAD ),
91 array( null, GIFHandler::METADATA_BAD ),
92 array( 'Something invalid!', GIFHandler::METADATA_BAD ),
93 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
94 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 ),
95 // @codingStandardsIgnoreEnd
99 /**
100 * @param string $filename
101 * @param string $expected Serialized array
102 * @dataProvider provideGetMetadata
103 * @covers GIFHandler::getMetadata
105 public function testGetMetadata( $filename, $expected ) {
106 $file = $this->dataFile( $filename, 'image/gif' );
107 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
108 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
111 public static function provideGetMetadata() {
112 return array(
113 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
114 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;}}' ),
115 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;}}' ),
116 // @codingStandardsIgnoreEnd
121 * @param string $filename
122 * @param string $expected Serialized array
123 * @dataProvider provideGetIndependentMetaArray
124 * @covers GIFHandler::getCommonMetaArray
126 public function testGetIndependentMetaArray( $filename, $expected ) {
127 $file = $this->dataFile( $filename, 'image/gif' );
128 $actual = $this->handler->getCommonMetaArray( $file );
129 $this->assertEquals( $expected, $actual );
132 public function provideGetIndependentMetaArray() {
133 return array(
134 array( 'nonanimated.gif', array(
135 'GIFFileComment' => array(
136 'GIF test file ⁕ Created with GIMP',
138 ) ),
139 array( 'animated-xmp.gif',
140 array(
141 'Artist' => 'Bawolff',
142 'ImageDescription' => array(
143 'x-default' => 'A file to test GIF',
144 '_type' => 'lang',
146 'SublocationDest' => 'The interwebs',
147 'GIFFileComment' =>
148 array(
149 'GIƒ·test·file',
156 private function dataFile( $name, $type ) {
157 return new UnregisteredLocalFile( false, $this->repo,
158 "mwstore://localtesting/data/$name", $type );