3 use MediaWiki\MainConfigNames
;
8 * @requires extension exif
10 class JpegTest
extends MediaWikiMediaTestCase
{
11 /** @var JpegHandler */
14 protected function setUp(): void
{
17 $this->overrideConfigValue( MainConfigNames
::ShowEXIF
, true );
19 $this->handler
= new JpegHandler
;
22 public function testInvalidFile() {
23 $file = $this->dataFile( 'README', 'image/jpeg' );
24 $res = $this->handler
->getSizeAndMetadataWithFallback( $file, $this->filePath
. 'README' );
25 $this->assertEquals( [ '_error' => ExifBitmapHandler
::BROKEN_FILE
], $res['metadata'] );
28 public function testJpegMetadataExtraction() {
29 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
30 $res = $this->handler
->getSizeAndMetadataWithFallback( $file, $this->filePath
. 'test.jpg' );
32 'ImageDescription' => 'Test file',
33 'XResolution' => '72/1',
34 'YResolution' => '72/1',
35 'ResolutionUnit' => 2,
36 'YCbCrPositioning' => 1,
37 'JPEGFileComment' => [
38 0 => 'Created with GIMP',
40 'MEDIAWIKI_EXIF_VERSION' => 2,
43 // Unserialize in case serialization format ever changes.
44 $this->assertEquals( $expected, $res['metadata'] );
48 * @covers \JpegHandler::getCommonMetaArray
50 public function testGetIndependentMetaArray() {
51 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
52 $res = $this->handler
->getCommonMetaArray( $file );
54 'ImageDescription' => 'Test file',
55 'XResolution' => '72/1',
56 'YResolution' => '72/1',
57 'ResolutionUnit' => 2,
58 'YCbCrPositioning' => 1,
59 'JPEGFileComment' => [
64 $this->assertEquals( $expected, $res );
68 * @dataProvider provideSwappingICCProfile
69 * @covers \JpegHandler::swapICCProfile
71 public function testSwappingICCProfile(
72 $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName
76 if ( !$wgExiftool ||
!is_file( $wgExiftool ) ) {
77 $this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" );
80 $this->overrideConfigValue( MainConfigNames
::UseTinyRGBForJPGThumbnails
, true );
82 $sourceFilepath = $this->filePath
. $sourceFilename;
83 $controlFilepath = $this->filePath
. $controlFilename;
84 $profileFilepath = $this->filePath
. $newProfileFilename;
85 $filepath = $this->getNewTempFile();
87 copy( $sourceFilepath, $filepath );
89 $this->handler
->swapICCProfile(
97 sha1( file_get_contents( $filepath ) ),
98 sha1( file_get_contents( $controlFilepath ) )
102 public static function provideSwappingICCProfile() {
104 // File with sRGB should end up with TinyRGB
111 // File with TinyRGB should be left unchanged
118 // File without profile should end up with TinyRGB
120 'missingprofile.jpg',
125 // Non-sRGB file should be left untouched