6 class ExifBitmapTest
extends MediaWikiMediaTestCase
{
9 * @var ExifBitmapHandler
13 protected function setUp() {
15 $this->checkPHPExtension( 'exif' );
17 $this->setMwGlobals( 'wgShowEXIF', true );
19 $this->handler
= new ExifBitmapHandler
;
23 * @covers ExifBitmapHandler::isMetadataValid
25 public function testIsOldBroken() {
26 $res = $this->handler
->isMetadataValid( null, ExifBitmapHandler
::OLD_BROKEN_FILE
);
27 $this->assertEquals( ExifBitmapHandler
::METADATA_COMPATIBLE
, $res );
31 * @covers ExifBitmapHandler::isMetadataValid
33 public function testIsBrokenFile() {
34 $res = $this->handler
->isMetadataValid( null, ExifBitmapHandler
::BROKEN_FILE
);
35 $this->assertEquals( ExifBitmapHandler
::METADATA_GOOD
, $res );
39 * @covers ExifBitmapHandler::isMetadataValid
41 public function testIsInvalid() {
42 $res = $this->handler
->isMetadataValid( null, 'Something Invalid Here.' );
43 $this->assertEquals( ExifBitmapHandler
::METADATA_BAD
, $res );
47 * @covers ExifBitmapHandler::isMetadataValid
49 public function testGoodMetadata() {
50 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
51 $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
52 // @codingStandardsIgnoreEnd
53 $res = $this->handler
->isMetadataValid( null, $meta );
54 $this->assertEquals( ExifBitmapHandler
::METADATA_GOOD
, $res );
58 * @covers ExifBitmapHandler::isMetadataValid
60 public function testIsOldGood() {
61 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
62 $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}';
63 // @codingStandardsIgnoreEnd
64 $res = $this->handler
->isMetadataValid( null, $meta );
65 $this->assertEquals( ExifBitmapHandler
::METADATA_COMPATIBLE
, $res );
69 * Handle metadata from paged tiff handler (gotten via instant commons) gracefully.
70 * @covers ExifBitmapHandler::isMetadataValid
72 public function testPagedTiffHandledGracefully() {
73 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
74 $meta = 'a:6:{s:9:"page_data";a:1:{i:1;a:5:{s:5:"width";i:643;s:6:"height";i:448;s:5:"alpha";s:4:"true";s:4:"page";i:1;s:6:"pixels";i:288064;}}s:10:"page_count";i:1;s:10:"first_page";i:1;s:9:"last_page";i:1;s:4:"exif";a:9:{s:10:"ImageWidth";i:643;s:11:"ImageLength";i:448;s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:4;s:12:"RowsPerStrip";i:50;s:19:"PlanarConfiguration";i:1;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}s:21:"TIFF_METADATA_VERSION";s:3:"1.4";}';
75 // @codingStandardsIgnoreEnd
76 $res = $this->handler
->isMetadataValid( null, $meta );
77 $this->assertEquals( ExifBitmapHandler
::METADATA_BAD
, $res );
81 * @covers ExifBitmapHandler::convertMetadataVersion
83 public function testConvertMetadataLatest() {
85 'foo' => [ 'First', 'Second', '_type' => 'ol' ],
86 'MEDIAWIKI_EXIF_VERSION' => 2
88 $res = $this->handler
->convertMetadataVersion( $metadata, 2 );
89 $this->assertEquals( $metadata, $res );
93 * @covers ExifBitmapHandler::convertMetadataVersion
95 public function testConvertMetadataToOld() {
97 'foo' => [ 'First', 'Second', '_type' => 'ol' ],
98 'bar' => [ 'First', 'Second', '_type' => 'ul' ],
99 'baz' => [ 'First', 'Second' ],
101 'MEDIAWIKI_EXIF_VERSION' => 2,
104 'foo' => "\n#First\n#Second",
105 'bar' => "\n*First\n*Second",
106 'baz' => "\n*First\n*Second",
108 'MEDIAWIKI_EXIF_VERSION' => 1,
110 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
111 $this->assertEquals( $expected, $res );
115 * @covers ExifBitmapHandler::convertMetadataVersion
117 public function testConvertMetadataSoftware() {
119 'Software' => [ [ 'GIMP', '1.1' ] ],
120 'MEDIAWIKI_EXIF_VERSION' => 2,
123 'Software' => 'GIMP (Version 1.1)',
124 'MEDIAWIKI_EXIF_VERSION' => 1,
126 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
127 $this->assertEquals( $expected, $res );
131 * @covers ExifBitmapHandler::convertMetadataVersion
133 public function testConvertMetadataSoftwareNormal() {
135 'Software' => [ "GIMP 1.2", "vim" ],
136 'MEDIAWIKI_EXIF_VERSION' => 2,
139 'Software' => "\n*GIMP 1.2\n*vim",
140 'MEDIAWIKI_EXIF_VERSION' => 1,
142 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
143 $this->assertEquals( $expected, $res );
147 * @dataProvider provideSwappingICCProfile
148 * @covers ExifBitmapHandler::swapICCProfile
150 public function testSwappingICCProfile(
151 $sourceFilename, $controlFilename, $newProfileFilename, $oldProfileName
155 if ( !$wgExiftool ||
!is_file( $wgExiftool ) ) {
156 $this->markTestSkipped( "Exiftool not installed, cannot test ICC profile swapping" );
159 $this->setMwGlobals( 'wgUseTinyRGBForJPGThumbnails', true );
161 $sourceFilepath = $this->filePath
. $sourceFilename;
162 $controlFilepath = $this->filePath
. $controlFilename;
163 $profileFilepath = $this->filePath
. $newProfileFilename;
164 $filepath = $this->getNewTempFile();
166 copy( $sourceFilepath, $filepath );
168 $file = $this->dataFile( $sourceFilename, 'image/jpeg' );
169 $this->handler
->swapICCProfile( $filepath, $oldProfileName, $profileFilepath );
172 sha1( file_get_contents( $filepath ) ),
173 sha1( file_get_contents( $controlFilepath ) )
177 public function provideSwappingICCProfile() {
179 // File with sRGB should end up with TinyRGB
184 'IEC 61966-2.1 Default RGB colour space - sRGB'
186 // File with TinyRGB should be left unchanged
191 'IEC 61966-2.1 Default RGB colour space - sRGB'
193 // File with no profile should be left unchanged
198 'IEC 61966-2.1 Default RGB colour space - sRGB'