Merge "Embed TinyRGB color profile when JPG EXIF Color Space = sRGB but no profile...
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegTest.php
index 05aed4a..b0f40ef 100644 (file)
@@ -51,4 +51,73 @@ class JpegTest extends MediaWikiMediaTestCase {
 
                $this->assertEquals( $res, $expected );
        }
+
+       /**
+        * @dataProvider provideSwappingICCProfile
+        * @covers ExifBitmapHandler::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'
+                       ]
+               ];
+       }
 }