Fix for r91885.
[lhc/web/wiklou.git] / tests / phpunit / includes / media / ExifBitmapTest.php
1 <?php
2
3 class ExifBitmapTest extends MediaWikiTestCase {
4
5 public function setUp() {
6 global $wgShowEXIF;
7 $this->showExif = $wgShowEXIF;
8 $wgShowEXIF = true;
9 }
10
11 public function tearDown() {
12 global $wgShowEXIF;
13 $wgShowEXIF = $this->showExif;
14 }
15
16 public function testIsOldBroken() {
17 if ( !wfDl( 'exif' ) ) {
18 $this->markTestIncomplete( "This test needs the exif extension." );
19 }
20 $handler = new ExifBitmapHandler;
21 $res = $handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
22 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
23 }
24 public function testIsBrokenFile() {
25 if ( !wfDl( 'exif' ) ) {
26 $this->markTestIncomplete( "This test needs the exif extension." );
27 }
28 $handler = new ExifBitmapHandler;
29 $res = $handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
30 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
31 }
32 public function testIsInvalid() {
33 if ( !wfDl( 'exif' ) ) {
34 $this->markTestIncomplete( "This test needs the exif extension." );
35 }
36 $handler = new ExifBitmapHandler;
37 $res = $handler->isMetadataValid( null, 'Something Invalid Here.' );
38 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
39 }
40 public function testGoodMetadata() {
41 if ( !wfDl( 'exif' ) ) {
42 $this->markTestIncomplete( "This test needs the exif extension." );
43 }
44 $handler = new ExifBitmapHandler;
45 $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;}';
46 $res = $handler->isMetadataValid( null, $meta );
47 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
48 }
49 public function testIsOldGood() {
50 if ( !wfDl( 'exif' ) ) {
51 $this->markTestIncomplete( "This test needs the exif extension." );
52 }
53 $handler = new ExifBitmapHandler;
54 $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;}';
55 $res = $handler->isMetadataValid( null, $meta );
56 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
57 }
58 // Handle metadata from paged tiff handler (gotten via instant commons)
59 // gracefully.
60 public function testPagedTiffHandledGracefully() {
61 if ( !wfDl( 'exif' ) ) {
62 $this->markTestIncomplete( "This test needs the exif extension." );
63 }
64 $handler = new ExifBitmapHandler;
65 $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";}';
66 $res = $handler->isMetadataValid( null, $meta );
67 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
68 }
69 }