X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fmedia%2FJpegTest.php;h=35d60723a6b14f808d9da07c1f4f89bfdf8cd3fe;hb=cdfe08439c3b5628060f3b9d9d7ca6523b1a2512;hp=05aed4ab218f5004ed4d3c0b901455f8ad0a086e;hpb=4b73a8b6fbb6da651af850a7d667e6e8d59e6fce;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/media/JpegTest.php b/tests/phpunit/includes/media/JpegTest.php index 05aed4ab21..35d60723a6 100644 --- a/tests/phpunit/includes/media/JpegTest.php +++ b/tests/phpunit/includes/media/JpegTest.php @@ -25,7 +25,7 @@ class JpegTest extends MediaWikiMediaTestCase { $file = $this->dataFile( 'test.jpg', 'image/jpeg' ); $res = $this->handler->getMetadata( $file, $this->filePath . 'test.jpg' ); // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong - $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;}'; + $expected = 'a:9:{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;s:5:"Width";i:20;s:6:"Height";i:20;}'; // @codingStandardsIgnoreEnd // Unserialize in case serialization format ever changes. @@ -39,6 +39,8 @@ class JpegTest extends MediaWikiMediaTestCase { $file = $this->dataFile( 'test.jpg', 'image/jpeg' ); $res = $this->handler->getCommonMetaArray( $file ); $expected = [ + 'Height' => 20, + 'Width' => 20, 'ImageDescription' => 'Test file', 'XResolution' => '72/1', 'YResolution' => '72/1', @@ -51,4 +53,73 @@ class JpegTest extends MediaWikiMediaTestCase { $this->assertEquals( $res, $expected ); } + + /** + * @dataProvider provideSwappingICCProfile + * @covers JpegHandler::swapICCProfile + */ + public function testSwappingICCProfile( + $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName + ) { + global $wgExiftool; + + if ( !$wgExiftool || !is_file( $wgExiftool ) ) { + $this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" ); + } + + $this->setMwGlobals( 'wgUseTinyRGBForJPGThumbnails', true ); + + $sourceFilepath = $this->filePath . $sourceFilename; + $controlFilepath = $this->filePath . $controlFilename; + $profileFilepath = $this->filePath . $newProfileFilename; + $filepath = $this->getNewTempFile(); + + copy( $sourceFilepath, $filepath ); + + $file = $this->dataFile( $sourceFilename, 'image/jpeg' ); + $this->handler->swapICCProfile( + $filepath, + [ 'sRGB', '-' ], + [ $oldProfileName ], + $profileFilepath + ); + + $this->assertEquals( + sha1( file_get_contents( $filepath ) ), + sha1( file_get_contents( $controlFilepath ) ) + ); + } + + public function provideSwappingICCProfile() { + return [ + // File with sRGB should end up with TinyRGB + [ + 'srgb.jpg', + 'tinyrgb.jpg', + 'tinyrgb.icc', + 'sRGB IEC61966-2.1' + ], + // File with TinyRGB should be left unchanged + [ + 'tinyrgb.jpg', + 'tinyrgb.jpg', + 'tinyrgb.icc', + 'sRGB IEC61966-2.1' + ], + // File without profile should end up with TinyRGB + [ + 'missingprofile.jpg', + 'tinyrgb.jpg', + 'tinyrgb.icc', + 'sRGB IEC61966-2.1' + ], + // Non-sRGB file should be left untouched + [ + 'adobergb.jpg', + 'adobergb.jpg', + 'tinyrgb.icc', + 'sRGB IEC61966-2.1' + ] + ]; + } }