MediaWiki REL1_32
JpegTest.php
Go to the documentation of this file.
1<?php
2
8
9 protected function setUp() {
10 parent::setUp();
11 $this->checkPHPExtension( 'exif' );
12
13 $this->setMwGlobals( 'wgShowEXIF', true );
14
15 $this->handler = new JpegHandler;
16 }
17
18 public function testInvalidFile() {
19 $file = $this->dataFile( 'README', 'image/jpeg' );
20 $res = $this->handler->getMetadata( $file, $this->filePath . 'README' );
21 $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
22 }
23
24 public function testJpegMetadataExtraction() {
25 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
26 $res = $this->handler->getMetadata( $file, $this->filePath . 'test.jpg' );
27 // phpcs:ignore Generic.Files.LineLength
28 $expected = 'a:7:{s:16:"ImageDescription";s:9:"Test file";s:11:"XResolution";s:4:"72/1";s:11:"YResolution";s:4:"72/1";s:14:"ResolutionUnit";i:2;s:16:"YCbCrPositioning";i:1;s:15:"JPEGFileComment";a:1:{i:0;s:17:"Created with GIMP";}s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
29
30 // Unserialize in case serialization format ever changes.
31 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
32 }
33
37 public function testGetIndependentMetaArray() {
38 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
39 $res = $this->handler->getCommonMetaArray( $file );
40 $expected = [
41 'ImageDescription' => 'Test file',
42 'XResolution' => '72/1',
43 'YResolution' => '72/1',
44 'ResolutionUnit' => 2,
45 'YCbCrPositioning' => 1,
46 'JPEGFileComment' => [
47 'Created with GIMP',
48 ],
49 ];
50
51 $this->assertEquals( $res, $expected );
52 }
53
58 public function testSwappingICCProfile(
59 $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName
60 ) {
61 global $wgExiftool;
62
63 if ( !$wgExiftool || !is_file( $wgExiftool ) ) {
64 $this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" );
65 }
66
67 $this->setMwGlobals( 'wgUseTinyRGBForJPGThumbnails', true );
68
69 $sourceFilepath = $this->filePath . $sourceFilename;
70 $controlFilepath = $this->filePath . $controlFilename;
71 $profileFilepath = $this->filePath . $newProfileFilename;
72 $filepath = $this->getNewTempFile();
73
74 copy( $sourceFilepath, $filepath );
75
76 $file = $this->dataFile( $sourceFilename, 'image/jpeg' );
77 $this->handler->swapICCProfile(
78 $filepath,
79 [ 'sRGB', '-' ],
80 [ $oldProfileName ],
81 $profileFilepath
82 );
83
84 $this->assertEquals(
85 sha1( file_get_contents( $filepath ) ),
86 sha1( file_get_contents( $controlFilepath ) )
87 );
88 }
89
90 public function provideSwappingICCProfile() {
91 return [
92 // File with sRGB should end up with TinyRGB
93 [
94 'srgb.jpg',
95 'tinyrgb.jpg',
96 'tinyrgb.icc',
97 'sRGB IEC61966-2.1'
98 ],
99 // File with TinyRGB should be left unchanged
100 [
101 'tinyrgb.jpg',
102 'tinyrgb.jpg',
103 'tinyrgb.icc',
104 'sRGB IEC61966-2.1'
105 ],
106 // File without profile should end up with TinyRGB
107 [
108 'missingprofile.jpg',
109 'tinyrgb.jpg',
110 'tinyrgb.icc',
111 'sRGB IEC61966-2.1'
112 ],
113 // Non-sRGB file should be left untouched
114 [
115 'adobergb.jpg',
116 'adobergb.jpg',
117 'tinyrgb.icc',
118 'sRGB IEC61966-2.1'
119 ]
120 ];
121 }
122}
unserialize( $serialized)
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
Definition COPYING.txt:87
$wgExiftool
Path to exiftool binary.
JPEG specific handler.
Media JpegHandler.
Definition JpegTest.php:7
testJpegMetadataExtraction()
Definition JpegTest.php:24
testSwappingICCProfile( $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName)
provideSwappingICCProfile JpegHandler::swapICCProfile
Definition JpegTest.php:58
testGetIndependentMetaArray()
JpegHandler::getCommonMetaArray.
Definition JpegTest.php:37
provideSwappingICCProfile()
Definition JpegTest.php:90
testInvalidFile()
Definition JpegTest.php:18
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)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
$res
Definition database.txt:21
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:960