MediaWiki  1.30.2
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  // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
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  // @codingStandardsIgnoreEnd
30 
31  // Unserialize in case serialization format ever changes.
32  $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
33  }
34 
38  public function testGetIndependentMetaArray() {
39  $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
40  $res = $this->handler->getCommonMetaArray( $file );
41  $expected = [
42  'ImageDescription' => 'Test file',
43  'XResolution' => '72/1',
44  'YResolution' => '72/1',
45  'ResolutionUnit' => 2,
46  'YCbCrPositioning' => 1,
47  'JPEGFileComment' => [
48  'Created with GIMP',
49  ],
50  ];
51 
52  $this->assertEquals( $res, $expected );
53  }
54 
59  public function testSwappingICCProfile(
60  $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName
61  ) {
63 
64  if ( !$wgExiftool || !is_file( $wgExiftool ) ) {
65  $this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" );
66  }
67 
68  $this->setMwGlobals( 'wgUseTinyRGBForJPGThumbnails', true );
69 
70  $sourceFilepath = $this->filePath . $sourceFilename;
71  $controlFilepath = $this->filePath . $controlFilename;
72  $profileFilepath = $this->filePath . $newProfileFilename;
73  $filepath = $this->getNewTempFile();
74 
75  copy( $sourceFilepath, $filepath );
76 
77  $file = $this->dataFile( $sourceFilename, 'image/jpeg' );
78  $this->handler->swapICCProfile(
79  $filepath,
80  [ 'sRGB', '-' ],
81  [ $oldProfileName ],
82  $profileFilepath
83  );
84 
85  $this->assertEquals(
86  sha1( file_get_contents( $filepath ) ),
87  sha1( file_get_contents( $controlFilepath ) )
88  );
89  }
90 
91  public function provideSwappingICCProfile() {
92  return [
93  // File with sRGB should end up with TinyRGB
94  [
95  'srgb.jpg',
96  'tinyrgb.jpg',
97  'tinyrgb.icc',
98  'sRGB IEC61966-2.1'
99  ],
100  // File with TinyRGB should be left unchanged
101  [
102  'tinyrgb.jpg',
103  'tinyrgb.jpg',
104  'tinyrgb.icc',
105  'sRGB IEC61966-2.1'
106  ],
107  // File without profile should end up with TinyRGB
108  [
109  'missingprofile.jpg',
110  'tinyrgb.jpg',
111  'tinyrgb.icc',
112  'sRGB IEC61966-2.1'
113  ],
114  // Non-sRGB file should be left untouched
115  [
116  'adobergb.jpg',
117  'adobergb.jpg',
118  'tinyrgb.icc',
119  'sRGB IEC61966-2.1'
120  ]
121  ];
122  }
123 }
copy
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
JpegTest\testJpegMetadataExtraction
testJpegMetadataExtraction()
Definition: JpegTest.php:24
$wgExiftool
$wgExiftool
Path to exiftool binary.
Definition: DefaultSettings.php:1098
unserialize
unserialize( $serialized)
Definition: ApiMessage.php:185
$res
$res
Definition: database.txt:21
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
MediaWikiMediaTestCase
Specificly for testing Media handlers.
Definition: MediaWikiMediaTestCase.php:5
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 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:781
JpegTest\testGetIndependentMetaArray
testGetIndependentMetaArray()
JpegHandler::getCommonMetaArray.
Definition: JpegTest.php:38
JpegTest\testInvalidFile
testInvalidFile()
Definition: JpegTest.php:18
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:457
MediaWikiMediaTestCase\dataFile
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
Definition: MediaWikiMediaTestCase.php:76
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
JpegTest\provideSwappingICCProfile
provideSwappingICCProfile()
Definition: JpegTest.php:91
JpegTest
Media JpegHandler.
Definition: JpegTest.php:7
JpegHandler
JPEG specific handler.
Definition: Jpeg.php:33
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1770
JpegTest\setUp
setUp()
Definition: JpegTest.php:9
ExifBitmapHandler\BROKEN_FILE
const BROKEN_FILE
Definition: ExifBitmap.php:31
JpegTest\testSwappingICCProfile
testSwappingICCProfile( $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName)
provideSwappingICCProfile JpegHandler::swapICCProfile
Definition: JpegTest.php:59