MediaWiki REL1_28
ExifBitmapTest.php
Go to the documentation of this file.
1<?php
2
7
11 protected $handler;
12
13 protected function setUp() {
14 parent::setUp();
15 $this->checkPHPExtension( 'exif' );
16
17 $this->setMwGlobals( 'wgShowEXIF', true );
18
19 $this->handler = new ExifBitmapHandler;
20
21 }
22
26 public function testIsOldBroken() {
27 $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
28 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
29 }
30
34 public function testIsBrokenFile() {
35 $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
36 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
37 }
38
42 public function testIsInvalid() {
43 $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
44 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
45 }
46
50 public function testGoodMetadata() {
51 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
52 $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
53 // @codingStandardsIgnoreEnd
54 $res = $this->handler->isMetadataValid( null, $meta );
55 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
56 }
57
61 public function testIsOldGood() {
62 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
63 $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}';
64 // @codingStandardsIgnoreEnd
65 $res = $this->handler->isMetadataValid( null, $meta );
66 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
67 }
68
74 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
75 $meta = 'a:6:{s:9:"page_data";a:1:{i:1;a:5:{s:5:"width";i:643;s:6:"height";i:448;s:5:"alpha";s:4:"true";s:4:"page";i:1;s:6:"pixels";i:288064;}}s:10:"page_count";i:1;s:10:"first_page";i:1;s:9:"last_page";i:1;s:4:"exif";a:9:{s:10:"ImageWidth";i:643;s:11:"ImageLength";i:448;s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:4;s:12:"RowsPerStrip";i:50;s:19:"PlanarConfiguration";i:1;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}s:21:"TIFF_METADATA_VERSION";s:3:"1.4";}';
76 // @codingStandardsIgnoreEnd
77 $res = $this->handler->isMetadataValid( null, $meta );
78 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
79 }
80
84 public function testConvertMetadataLatest() {
85 $metadata = [
86 'foo' => [ 'First', 'Second', '_type' => 'ol' ],
87 'MEDIAWIKI_EXIF_VERSION' => 2
88 ];
89 $res = $this->handler->convertMetadataVersion( $metadata, 2 );
90 $this->assertEquals( $metadata, $res );
91 }
92
96 public function testConvertMetadataToOld() {
97 $metadata = [
98 'foo' => [ 'First', 'Second', '_type' => 'ol' ],
99 'bar' => [ 'First', 'Second', '_type' => 'ul' ],
100 'baz' => [ 'First', 'Second' ],
101 'fred' => 'Single',
102 'MEDIAWIKI_EXIF_VERSION' => 2,
103 ];
104 $expected = [
105 'foo' => "\n#First\n#Second",
106 'bar' => "\n*First\n*Second",
107 'baz' => "\n*First\n*Second",
108 'fred' => 'Single',
109 'MEDIAWIKI_EXIF_VERSION' => 1,
110 ];
111 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
112 $this->assertEquals( $expected, $res );
113 }
114
118 public function testConvertMetadataSoftware() {
119 $metadata = [
120 'Software' => [ [ 'GIMP', '1.1' ] ],
121 'MEDIAWIKI_EXIF_VERSION' => 2,
122 ];
123 $expected = [
124 'Software' => 'GIMP (Version 1.1)',
125 'MEDIAWIKI_EXIF_VERSION' => 1,
126 ];
127 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
128 $this->assertEquals( $expected, $res );
129 }
130
135 $metadata = [
136 'Software' => [ "GIMP 1.2", "vim" ],
137 'MEDIAWIKI_EXIF_VERSION' => 2,
138 ];
139 $expected = [
140 'Software' => "\n*GIMP 1.2\n*vim",
141 'MEDIAWIKI_EXIF_VERSION' => 1,
142 ];
143 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
144 $this->assertEquals( $expected, $res );
145 }
146
151 public function testSwappingICCProfile(
152 $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName
153 ) {
155
156 if ( !$wgExiftool || !is_file( $wgExiftool ) ) {
157 $this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" );
158 }
159
160 $this->setMwGlobals( 'wgUseTinyRGBForJPGThumbnails', true );
161
162 $sourceFilepath = $this->filePath . $sourceFilename;
163 $controlFilepath = $this->filePath . $controlFilename;
164 $profileFilepath = $this->filePath . $newProfileFilename;
165 $filepath = $this->getNewTempFile();
166
167 copy( $sourceFilepath, $filepath );
168
169 $file = $this->dataFile( $sourceFilename, 'image/jpeg' );
170 $this->handler->swapICCProfile( $filepath, $oldProfileName, $profileFilepath );
171
172 $this->assertEquals(
173 sha1( file_get_contents( $filepath ) ),
174 sha1( file_get_contents( $controlFilepath ) )
175 );
176 }
177
178 public function provideSwappingICCProfile() {
179 return [
180 // File with sRGB should end up with TinyRGB
181 [
182 'srgb.jpg',
183 'tinyrgb.jpg',
184 'tinyrgb.icc',
185 'IEC 61966-2.1 Default RGB colour space - sRGB'
186 ],
187 // File with TinyRGB should be left unchanged
188 [
189 'tinyrgb.jpg',
190 'tinyrgb.jpg',
191 'tinyrgb.icc',
192 'IEC 61966-2.1 Default RGB colour space - sRGB'
193 ],
194 // File with no profile should be left unchanged
195 [
196 'test.jpg',
197 'test.jpg',
198 'tinyrgb.icc',
199 'IEC 61966-2.1 Default RGB colour space - sRGB'
200 ]
201 ];
202 }
203}
$wgExiftool
Path to exiftool binary.
Stuff specific to JPEG and (built-in) TIFF handler.
testIsOldGood()
ExifBitmapHandler::isMetadataValid.
testIsOldBroken()
ExifBitmapHandler::isMetadataValid.
testConvertMetadataToOld()
ExifBitmapHandler::convertMetadataVersion.
testIsInvalid()
ExifBitmapHandler::isMetadataValid.
testSwappingICCProfile( $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName)
provideSwappingICCProfile ExifBitmapHandler::swapICCProfile
testIsBrokenFile()
ExifBitmapHandler::isMetadataValid.
testConvertMetadataSoftware()
ExifBitmapHandler::convertMetadataVersion.
ExifBitmapHandler $handler
testConvertMetadataLatest()
ExifBitmapHandler::convertMetadataVersion.
testPagedTiffHandledGracefully()
Handle metadata from paged tiff handler (gotten via instant commons) gracefully.
testConvertMetadataSoftwareNormal()
ExifBitmapHandler::convertMetadataVersion.
testGoodMetadata()
ExifBitmapHandler::isMetadataValid.
const METADATA_COMPATIBLE
const METADATA_GOOD
Specificly for testing Media handlers.
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
getNewTempFile()
Obtains a new temporary file name.
setMwGlobals( $pairs, $value=null)
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
$res
Definition database.txt:21
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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:952
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Definition LICENSE.txt:11
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:37