MediaWiki  REL1_19
ExifBitmapTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class ExifBitmapTest extends MediaWikiTestCase {
00004 
00005         public function setUp() {
00006                 global $wgShowEXIF;
00007                 $this->showExif = $wgShowEXIF;
00008                 $wgShowEXIF = true;
00009                 $this->handler = new ExifBitmapHandler;
00010                 if ( !wfDl( 'exif' ) ) {
00011                         $this->markTestSkipped( "This test needs the exif extension." );
00012                 }
00013         }
00014 
00015         public function tearDown() {
00016                 global $wgShowEXIF;
00017                 $wgShowEXIF = $this->showExif;
00018         }
00019 
00020         public function testIsOldBroken() {
00021                 $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
00022                 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
00023         }
00024         public function testIsBrokenFile() {
00025                 $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
00026                 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
00027         }
00028         public function testIsInvalid() {
00029                 $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
00030                 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
00031         }
00032         public function testGoodMetadata() {
00033                 $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;}';
00034                 $res = $this->handler->isMetadataValid( null, $meta );
00035                 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
00036         }
00037         public function testIsOldGood() {
00038                 $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;}';
00039                 $res = $this->handler->isMetadataValid( null, $meta );
00040                 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
00041         }
00042         // Handle metadata from paged tiff handler (gotten via instant commons)
00043         // gracefully.
00044         public function testPagedTiffHandledGracefully() {
00045                 $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";}';
00046                 $res = $this->handler->isMetadataValid( null, $meta );
00047                 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
00048         }
00049 
00050         function testConvertMetadataLatest() {
00051                 $metadata = array(
00052                                 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
00053                                 'MEDIAWIKI_EXIF_VERSION' => 2
00054                          );
00055                 $res = $this->handler->convertMetadataVersion( $metadata, 2 );
00056                 $this->assertEquals( $metadata, $res );
00057         }
00058         function testConvertMetadataToOld() {
00059                 $metadata = array(
00060                         'foo' => array( 'First', 'Second', '_type' => 'ol' ),
00061                         'bar' => array( 'First', 'Second', '_type' => 'ul' ),
00062                         'baz' => array( 'First', 'Second' ),
00063                         'fred' => 'Single',
00064                         'MEDIAWIKI_EXIF_VERSION' => 2,
00065                 );
00066                 $expected = array(
00067                         'foo' => "\n#First\n#Second",
00068                         'bar' => "\n*First\n*Second",
00069                         'baz' => "\n*First\n*Second",
00070                         'fred' => 'Single',
00071                         'MEDIAWIKI_EXIF_VERSION' => 1,
00072                 );
00073                 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
00074                 $this->assertEquals( $expected, $res );
00075         }
00076         function testConvertMetadataSoftware() {
00077                 $metadata = array(
00078                         'Software' => array( array('GIMP', '1.1' ) ),
00079                         'MEDIAWIKI_EXIF_VERSION' => 2,
00080                 );
00081                 $expected = array(
00082                         'Software' => 'GIMP (Version 1.1)',
00083                         'MEDIAWIKI_EXIF_VERSION' => 1,
00084                 );
00085                 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
00086                 $this->assertEquals( $expected, $res );
00087         }
00088         function testConvertMetadataSoftwareNormal() {
00089                 $metadata = array(
00090                         'Software' => array( "GIMP 1.2", "vim" ),
00091                         'MEDIAWIKI_EXIF_VERSION' => 2,
00092                 );
00093                 $expected = array(
00094                         'Software' => "\n*GIMP 1.2\n*vim",
00095                         'MEDIAWIKI_EXIF_VERSION' => 1,
00096                 );
00097                 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
00098                 $this->assertEquals( $expected, $res );
00099         }
00100 }