MediaWiki  1.27.1
GIFTest.php
Go to the documentation of this file.
1 <?php
2 
7 
9  protected $handler;
10 
11  protected function setUp() {
12  parent::setUp();
13 
14  $this->handler = new GIFHandler();
15  }
16 
20  public function testInvalidFile() {
21  $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
22  $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
23  }
24 
31  public function testIsAnimanted( $filename, $expected ) {
32  $file = $this->dataFile( $filename, 'image/gif' );
33  $actual = $this->handler->isAnimatedImage( $file );
34  $this->assertEquals( $expected, $actual );
35  }
36 
37  public static function provideIsAnimated() {
38  return [
39  [ 'animated.gif', true ],
40  [ 'nonanimated.gif', false ],
41  ];
42  }
43 
50  public function testGetImageArea( $filename, $expected ) {
51  $file = $this->dataFile( $filename, 'image/gif' );
52  $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
53  $this->assertEquals( $expected, $actual );
54  }
55 
56  public static function provideGetImageArea() {
57  return [
58  [ 'animated.gif', 5400 ],
59  [ 'nonanimated.gif', 1350 ],
60  ];
61  }
62 
69  public function testIsMetadataValid( $metadata, $expected ) {
70  $actual = $this->handler->isMetadataValid( null, $metadata );
71  $this->assertEquals( $expected, $actual );
72  }
73 
74  public static function provideIsMetadataValid() {
75  return [
78  [ null, GIFHandler::METADATA_BAD ],
79  [ 'Something invalid!', GIFHandler::METADATA_BAD ],
80  // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
81  [
82  '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;}}',
84  ],
85  // @codingStandardsIgnoreEnd
86  ];
87  }
88 
95  public function testGetMetadata( $filename, $expected ) {
96  $file = $this->dataFile( $filename, 'image/gif' );
97  $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
98  $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
99  }
100 
101  public static function provideGetMetadata() {
102  return [
103  // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
104  [
105  'nonanimated.gif',
106  '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;}}'
107  ],
108  [
109  'animated-xmp.gif',
110  '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;}}'
111  ],
112  // @codingStandardsIgnoreEnd
113  ];
114  }
115 
122  public function testGetIndependentMetaArray( $filename, $expected ) {
123  $file = $this->dataFile( $filename, 'image/gif' );
124  $actual = $this->handler->getCommonMetaArray( $file );
125  $this->assertEquals( $expected, $actual );
126  }
127 
128  public static function provideGetIndependentMetaArray() {
129  return [
130  [ 'nonanimated.gif', [
131  'GIFFileComment' => [
132  'GIF test file ⁕ Created with GIMP',
133  ],
134  ] ],
135  [ 'animated-xmp.gif',
136  [
137  'Artist' => 'Bawolff',
138  'ImageDescription' => [
139  'x-default' => 'A file to test GIF',
140  '_type' => 'lang',
141  ],
142  'SublocationDest' => 'The interwebs',
143  'GIFFileComment' =>
144  [
145  'GIƒ·test·file',
146  ],
147  ]
148  ],
149  ];
150  }
151 
157  public function testGetLength( $filename, $expectedLength ) {
158  $file = $this->dataFile( $filename, 'image/gif' );
159  $actualLength = $file->getLength();
160  $this->assertEquals( $expectedLength, $actualLength, '', 0.00001 );
161  }
162 
163  public function provideGetLength() {
164  return [
165  [ 'animated.gif', 2.4 ],
166  [ 'animated-xmp.gif', 2.4 ],
167  [ 'nonanimated', 0.0 ],
168  [ 'Bishzilla_blink.gif', 1.4 ],
169  ];
170  }
171 }
testGetMetadata($filename, $expected)
Definition: GIFTest.php:95
static provideGetMetadata()
Definition: GIFTest.php:101
testGetImageArea($filename, $expected)
Definition: GIFTest.php:50
static provideGetImageArea()
Definition: GIFTest.php:56
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
const METADATA_BAD
testIsMetadataValid($metadata, $expected)
Definition: GIFTest.php:69
testInvalidFile()
GIFHandler::getMetadata.
Definition: GIFTest.php:20
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1798
static provideGetIndependentMetaArray()
Definition: GIFTest.php:128
testGetLength($filename, $expectedLength)
Definition: GIFTest.php:157
unserialize($serialized)
Definition: ApiMessage.php:102
static provideIsMetadataValid()
Definition: GIFTest.php:74
testGetIndependentMetaArray($filename, $expected)
Definition: GIFTest.php:122
$res
Definition: database.txt:21
GIFHandler $handler
Definition: GIFTest.php:9
dataFile($name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
const METADATA_GOOD
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves set to a MediaTransformOutput the error message to be returned in an array you should do so by altering $wgNamespaceProtection and $wgNamespaceContentModels outside the handler
Definition: hooks.txt:762
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
const BROKEN_FILE
Definition: GIF.php:30
testIsAnimanted($filename, $expected)
Definition: GIFTest.php:31
Handler for GIF images.
Definition: GIF.php:29
Media.
Definition: GIFTest.php:6
static provideIsAnimated()
Definition: GIFTest.php:37
Specificly for testing Media handlers.