MediaWiki  REL1_22
ExifBitmapTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class ExifBitmapTest extends MediaWikiTestCase {
00004 
00008     protected $handler;
00009 
00010     protected function setUp() {
00011         parent::setUp();
00012         if ( !extension_loaded( 'exif' ) ) {
00013             $this->markTestSkipped( "This test needs the exif extension." );
00014         }
00015 
00016         $this->setMwGlobals( 'wgShowEXIF', true );
00017 
00018         $this->handler = new ExifBitmapHandler;
00019 
00020     }
00021 
00025     public function testIsOldBroken() {
00026         $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
00027         $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
00028     }
00029 
00033     public function testIsBrokenFile() {
00034         $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
00035         $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
00036     }
00037 
00041     public function testIsInvalid() {
00042         $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
00043         $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
00044     }
00045 
00049     public function testGoodMetadata() {
00050         $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;}';
00051         $res = $this->handler->isMetadataValid( null, $meta );
00052         $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
00053     }
00054 
00058     public function testIsOldGood() {
00059         $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;}';
00060         $res = $this->handler->isMetadataValid( null, $meta );
00061         $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
00062     }
00063 
00068     public function testPagedTiffHandledGracefully() {
00069         $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";}';
00070         $res = $this->handler->isMetadataValid( null, $meta );
00071         $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
00072     }
00073 
00077     public function testConvertMetadataLatest() {
00078         $metadata = array(
00079             'foo' => array( 'First', 'Second', '_type' => 'ol' ),
00080             'MEDIAWIKI_EXIF_VERSION' => 2
00081         );
00082         $res = $this->handler->convertMetadataVersion( $metadata, 2 );
00083         $this->assertEquals( $metadata, $res );
00084     }
00085 
00089     public function testConvertMetadataToOld() {
00090         $metadata = array(
00091             'foo' => array( 'First', 'Second', '_type' => 'ol' ),
00092             'bar' => array( 'First', 'Second', '_type' => 'ul' ),
00093             'baz' => array( 'First', 'Second' ),
00094             'fred' => 'Single',
00095             'MEDIAWIKI_EXIF_VERSION' => 2,
00096         );
00097         $expected = array(
00098             'foo' => "\n#First\n#Second",
00099             'bar' => "\n*First\n*Second",
00100             'baz' => "\n*First\n*Second",
00101             'fred' => 'Single',
00102             'MEDIAWIKI_EXIF_VERSION' => 1,
00103         );
00104         $res = $this->handler->convertMetadataVersion( $metadata, 1 );
00105         $this->assertEquals( $expected, $res );
00106     }
00107 
00111     public function testConvertMetadataSoftware() {
00112         $metadata = array(
00113             'Software' => array( array( 'GIMP', '1.1' ) ),
00114             'MEDIAWIKI_EXIF_VERSION' => 2,
00115         );
00116         $expected = array(
00117             'Software' => 'GIMP (Version 1.1)',
00118             'MEDIAWIKI_EXIF_VERSION' => 1,
00119         );
00120         $res = $this->handler->convertMetadataVersion( $metadata, 1 );
00121         $this->assertEquals( $expected, $res );
00122     }
00123 
00127     public function testConvertMetadataSoftwareNormal() {
00128         $metadata = array(
00129             'Software' => array( "GIMP 1.2", "vim" ),
00130             'MEDIAWIKI_EXIF_VERSION' => 2,
00131         );
00132         $expected = array(
00133             'Software' => "\n*GIMP 1.2\n*vim",
00134             'MEDIAWIKI_EXIF_VERSION' => 1,
00135         );
00136         $res = $this->handler->convertMetadataVersion( $metadata, 1 );
00137         $this->assertEquals( $expected, $res );
00138     }
00139 }