| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
class JpegTest extends MediaWikiMediaTestCase { |
| 11 |
|
| 12 |
private $handler; |
| 13 |
|
| 14 |
protected function setUp(): void { |
| 15 |
parent::setUp(); |
| 16 |
|
| 17 |
$this->overrideConfigValue( MainConfigNames::ShowEXIF, true ); |
| 18 |
|
| 19 |
$this->handler = new JpegHandler; |
| 20 |
} |
| 21 |
|
| 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'] ); |
| 26 |
} |
| 27 |
|
| 28 |
public function testJpegMetadataExtraction() { |
| 29 |
$file = $this->dataFile( 'test.jpg', 'image/jpeg' ); |
| 30 |
$res = $this->handler->getSizeAndMetadataWithFallback( $file, $this->filePath . 'test.jpg' ); |
| 31 |
$expected = [ |
| 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', |
| 39 |
], |
| 40 |
'MEDIAWIKI_EXIF_VERSION' => 2, |
| 41 |
]; |
| 42 |
|
| 43 |
|
| 44 |
$this->assertEquals( $expected, $res['metadata'] ); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function testGetIndependentMetaArray() { |
| 51 |
$file = $this->dataFile( 'test.jpg', 'image/jpeg' ); |
| 52 |
$res = $this->handler->getCommonMetaArray( $file ); |
| 53 |
$expected = [ |
| 54 |
'ImageDescription' => 'Test file', |
| 55 |
'XResolution' => '72/1', |
| 56 |
'YResolution' => '72/1', |
| 57 |
'ResolutionUnit' => 2, |
| 58 |
'YCbCrPositioning' => 1, |
| 59 |
'JPEGFileComment' => [ |
| 60 |
'Created with GIMP', |
| 61 |
], |
| 62 |
]; |
| 63 |
|
| 64 |
$this->assertEquals( $expected, $res ); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function testSwappingICCProfile( |
| 72 |
$sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName |
| 73 |
) { |
| 74 |
global $wgExiftool; |
| 75 |
|
| 76 |
if ( !$wgExiftool || !is_file( $wgExiftool ) ) { |
| 77 |
$this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" ); |
| 78 |
} |
| 79 |
|
| 80 |
$this->overrideConfigValue( MainConfigNames::UseTinyRGBForJPGThumbnails, true ); |
| 81 |
|
| 82 |
$sourceFilepath = $this->filePath . $sourceFilename; |
| 83 |
$controlFilepath = $this->filePath . $controlFilename; |
| 84 |
$profileFilepath = $this->filePath . $newProfileFilename; |
| 85 |
$filepath = $this->getNewTempFile(); |
| 86 |
|
| 87 |
copy( $sourceFilepath, $filepath ); |
| 88 |
|
| 89 |
$this->handler->swapICCProfile( |
| 90 |
$filepath, |
| 91 |
[ 'sRGB', '-' ], |
| 92 |
[ $oldProfileName ], |
| 93 |
$profileFilepath |
| 94 |
); |
| 95 |
|
| 96 |
$this->assertEquals( |
| 97 |
sha1( file_get_contents( $filepath ) ), |
| 98 |
sha1( file_get_contents( $controlFilepath ) ) |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
public static function provideSwappingICCProfile() { |
| 103 |
return [ |
| 104 |
|
| 105 |
[ |
| 106 |
'srgb.jpg', |
| 107 |
'tinyrgb.jpg', |
| 108 |
'tinyrgb.icc', |
| 109 |
'sRGB IEC61966-2.1' |
| 110 |
], |
| 111 |
|
| 112 |
[ |
| 113 |
'tinyrgb.jpg', |
| 114 |
'tinyrgb.jpg', |
| 115 |
'tinyrgb.icc', |
| 116 |
'sRGB IEC61966-2.1' |
| 117 |
], |
| 118 |
|
| 119 |
[ |
| 120 |
'missingprofile.jpg', |
| 121 |
'tinyrgb.jpg', |
| 122 |
'tinyrgb.icc', |
| 123 |
'sRGB IEC61966-2.1' |
| 124 |
], |
| 125 |
|
| 126 |
[ |
| 127 |
'adobergb.jpg', |
| 128 |
'adobergb.jpg', |
| 129 |
'tinyrgb.icc', |
| 130 |
'sRGB IEC61966-2.1' |
| 131 |
] |
| 132 |
]; |
| 133 |
} |
| 134 |
} |