MediaWiki  1.33.0
PNGHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
7 
9  protected $handler;
10 
11  protected function setUp() {
12  parent::setUp();
13  $this->handler = new PNGHandler();
14  }
15 
19  public function testInvalidFile() {
20  $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
21  $this->assertEquals( PNGHandler::BROKEN_FILE, $res );
22  }
23 
30  public function testIsAnimanted( $filename, $expected ) {
31  $file = $this->dataFile( $filename, 'image/png' );
32  $actual = $this->handler->isAnimatedImage( $file );
33  $this->assertEquals( $expected, $actual );
34  }
35 
36  public static function provideIsAnimated() {
37  return [
38  [ 'Animated_PNG_example_bouncing_beach_ball.png', true ],
39  [ '1bit-png.png', false ],
40  ];
41  }
42 
49  public function testGetImageArea( $filename, $expected ) {
50  $file = $this->dataFile( $filename, 'image/png' );
51  $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
52  $this->assertEquals( $expected, $actual );
53  }
54 
55  public static function provideGetImageArea() {
56  return [
57  [ '1bit-png.png', 2500 ],
58  [ 'greyscale-png.png', 2500 ],
59  [ 'Png-native-test.png', 126000 ],
60  [ 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ],
61  ];
62  }
63 
70  public function testIsMetadataValid( $metadata, $expected ) {
71  $actual = $this->handler->isMetadataValid( null, $metadata );
72  $this->assertEquals( $expected, $actual );
73  }
74 
75  public static function provideIsMetadataValid() {
76  // phpcs:disable Generic.Files.LineLength
77  return [
80  [ null, PNGHandler::METADATA_BAD ],
81  [ 'Something invalid!', PNGHandler::METADATA_BAD ],
82  [
83  'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}',
85  ],
86  ];
87  // phpcs:enable
88  }
89 
96  public function testGetMetadata( $filename, $expected ) {
97  $file = $this->dataFile( $filename, 'image/png' );
98  $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
99 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
100  $this->assertEquals( ( $expected ), ( $actual ) );
101  }
102 
103  public static function provideGetMetadata() {
104  // phpcs:disable Generic.Files.LineLength
105  return [
106  [
107  'rgb-na-png.png',
108  'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}'
109  ],
110  [
111  'xmp.png',
112  'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:1;s:9:"colorType";s:14:"index-coloured";s:8:"metadata";a:2:{s:12:"SerialNumber";s:9:"123456789";s:15:"_MW_PNG_VERSION";i:1;}}'
113  ],
114  ];
115  // phpcs:enable
116  }
117 
124  public function testGetIndependentMetaArray( $filename, $expected ) {
125  $file = $this->dataFile( $filename, 'image/png' );
126  $actual = $this->handler->getCommonMetaArray( $file );
127  $this->assertEquals( $expected, $actual );
128  }
129 
130  public static function provideGetIndependentMetaArray() {
131  return [
132  [ 'rgb-na-png.png', [] ],
133  [ 'xmp.png',
134  [
135  'SerialNumber' => '123456789',
136  ]
137  ],
138  ];
139  }
140 
147  public function testGetLength( $filename, $expectedLength ) {
148  $file = $this->dataFile( $filename, 'image/png' );
149  $actualLength = $file->getLength();
150  $this->assertEquals( $expectedLength, $actualLength, '', 0.00001 );
151  }
152 
153  public function provideGetLength() {
154  return [
155  [ 'Animated_PNG_example_bouncing_beach_ball.png', 1.5 ],
156  [ 'Png-native-test.png', 0.0 ],
157  [ 'greyscale-png.png', 0.0 ],
158  [ '1bit-png.png', 0.0 ],
159  ];
160  }
161 }
PNGHandlerTest
Media.
Definition: PNGHandlerTest.php:6
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Definition: router.php:42
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
PNGHandlerTest\provideGetIndependentMetaArray
static provideGetIndependentMetaArray()
Definition: PNGHandlerTest.php:130
PNGHandlerTest\provideGetImageArea
static provideGetImageArea()
Definition: PNGHandlerTest.php:55
PNGHandler\BROKEN_FILE
const BROKEN_FILE
Definition: PNGHandler.php:30
$res
$res
Definition: database.txt:21
MediaWikiMediaTestCase\dataFile
dataFile( $name, $type=false)
Utility function: Get a new file object for a file on disk but not actually in db.
Definition: MediaWikiMediaTestCase.php:76
PNGHandlerTest\provideGetMetadata
static provideGetMetadata()
Definition: PNGHandlerTest.php:103
php
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
PNGHandlerTest\testIsMetadataValid
testIsMetadataValid( $metadata, $expected)
Definition: PNGHandlerTest.php:70
PNGHandlerTest\testIsAnimanted
testIsAnimanted( $filename, $expected)
Definition: PNGHandlerTest.php:30
MediaWikiMediaTestCase
Specificly for testing Media handlers.
Definition: MediaWikiMediaTestCase.php:5
PNGHandlerTest\testInvalidFile
testInvalidFile()
PNGHandler::getMetadata.
Definition: PNGHandlerTest.php:19
PNGHandlerTest\provideIsMetadataValid
static provideIsMetadataValid()
Definition: PNGHandlerTest.php:75
PNGHandlerTest\setUp
setUp()
Definition: PNGHandlerTest.php:11
PNGHandlerTest\provideGetLength
provideGetLength()
Definition: PNGHandlerTest.php:153
PNGHandlerTest\provideIsAnimated
static provideIsAnimated()
Definition: PNGHandlerTest.php:36
handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
PNGHandler
Handler for PNG images.
Definition: PNGHandler.php:29
PNGHandlerTest\testGetLength
testGetLength( $filename, $expectedLength)
Definition: PNGHandlerTest.php:147
PNGHandlerTest\testGetImageArea
testGetImageArea( $filename, $expected)
Definition: PNGHandlerTest.php:49
PNGHandlerTest\testGetIndependentMetaArray
testGetIndependentMetaArray( $filename, $expected)
Definition: PNGHandlerTest.php:124
MediaHandler\METADATA_BAD
const METADATA_BAD
Definition: MediaHandler.php:33
true
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:1985
PNGHandlerTest\testGetMetadata
testGetMetadata( $filename, $expected)
Definition: PNGHandlerTest.php:96
PNGHandlerTest\$handler
PNGHandler $handler
Definition: PNGHandlerTest.php:9
MediaHandler\METADATA_GOOD
const METADATA_GOOD
Definition: MediaHandler.php:32