7 class JpegTest
extends MediaWikiMediaTestCase
{
9 protected function setUp() {
11 $this->checkPHPExtension( 'exif' );
13 $this->setMwGlobals( 'wgShowEXIF', true );
15 $this->handler
= new JpegHandler
;
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 );
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;}';
30 // Unserialize in case serialization format ever changes.
31 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
35 * @covers JpegHandler::getCommonMetaArray
37 public function testGetIndependentMetaArray() {
38 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
39 $res = $this->handler
->getCommonMetaArray( $file );
41 'ImageDescription' => 'Test file',
42 'XResolution' => '72/1',
43 'YResolution' => '72/1',
44 'ResolutionUnit' => 2,
45 'YCbCrPositioning' => 1,
46 'JPEGFileComment' => [
51 $this->assertEquals( $res, $expected );
55 * @dataProvider provideSwappingICCProfile
56 * @covers JpegHandler::swapICCProfile
58 public function testSwappingICCProfile(
59 $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName
63 if ( !$wgExiftool ||
!is_file( $wgExiftool ) ) {
64 $this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" );
67 $this->setMwGlobals( 'wgUseTinyRGBForJPGThumbnails', true );
69 $sourceFilepath = $this->filePath
. $sourceFilename;
70 $controlFilepath = $this->filePath
. $controlFilename;
71 $profileFilepath = $this->filePath
. $newProfileFilename;
72 $filepath = $this->getNewTempFile();
74 copy( $sourceFilepath, $filepath );
76 $file = $this->dataFile( $sourceFilename, 'image/jpeg' );
77 $this->handler
->swapICCProfile(
85 sha1( file_get_contents( $filepath ) ),
86 sha1( file_get_contents( $controlFilepath ) )
90 public function provideSwappingICCProfile() {
92 // File with sRGB should end up with TinyRGB
99 // File with TinyRGB should be left unchanged
106 // File without profile should end up with TinyRGB
108 'missingprofile.jpg',
113 // Non-sRGB file should be left untouched