MediaWiki  REL1_19
BitmapMetadataHandlerTest.php
Go to the documentation of this file.
00001 <?php
00002 class BitmapMetadataHandlerTest extends MediaWikiTestCase {
00003 
00004         public function setUp() {
00005                 $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
00006         }
00007 
00016         public function testMultilingualCascade() {
00017                 if ( !wfDl( 'exif' ) ) {
00018                         $this->markTestSkipped( "This test needs the exif extension." );
00019                 }
00020                 if ( !wfDl( 'xml' ) ) {
00021                         $this->markTestSkipped( "This test needs the xml extension." );
00022                 }
00023                 global $wgShowEXIF;
00024                 $oldExif = $wgShowEXIF;
00025                 $wgShowEXIF = true;
00026 
00027                 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00028                         '/Xmp-exif-multilingual_test.jpg' );
00029 
00030                 $expected = array(
00031                         'x-default' => 'right(iptc)',
00032                         'en'        => 'right translation',
00033                         '_type'     => 'lang'
00034                 );
00035                 
00036                 $this->assertArrayHasKey( 'ImageDescription', $meta,
00037                         'Did not extract any ImageDescription info?!' );
00038 
00039                 $this->assertEquals( $expected, $meta['ImageDescription'] );
00040 
00041                 $wgShowEXIF = $oldExif;
00042         }
00043 
00051         public function testJpegComment() {
00052                 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00053                         'jpeg-comment-utf.jpg' );
00054 
00055                 $this->assertEquals( 'UTF-8 JPEG Comment — ¼',
00056                         $meta['JPEGFileComment'][0] );
00057         }
00058 
00063         public function testBadIPTC() {
00064                 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00065                         'iptc-invalid-psir.jpg' );
00066                 $this->assertEquals( 'Created with GIMP', $meta['JPEGFileComment'][0] );
00067         }
00068 
00069         public function testIPTCDates() {
00070                 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00071                         'iptc-timetest.jpg' );
00072 
00073                 $this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] );
00074                 $this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] );
00075         }
00076         /* File has an invalid time (+ one valid but really weird time)
00077          * that shouldn't be included
00078          */
00079         public function testIPTCDatesInvalid() {
00080                 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00081                         'iptc-timetest-invalid.jpg' );
00082 
00083                 $this->assertEquals( '1845:03:02 00:01:02', $meta['DateTimeOriginal'] );
00084                 $this->assertFalse( isset( $meta['DateTimeDigitized'] ) );
00085         }
00086 
00092         public function testMerging() {
00093                 $merger = new BitmapMetadataHandler();
00094                 $merger->addMetadata( array( 'foo' => 'xmp' ), 'xmp-general' );
00095                 $merger->addMetadata( array( 'bar' => 'xmp' ), 'xmp-general' );
00096                 $merger->addMetadata( array( 'baz' => 'xmp' ), 'xmp-general' );
00097                 $merger->addMetadata( array( 'fred' => 'xmp' ), 'xmp-general' );
00098                 $merger->addMetadata( array( 'foo' => 'iptc (hash)' ), 'iptc-good-hash' );
00099                 $merger->addMetadata( array( 'bar' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
00100                 $merger->addMetadata( array( 'baz' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
00101                 $merger->addMetadata( array( 'fred' => 'iptc (no hash)' ), 'iptc-no-hash' );
00102                 $merger->addMetadata( array( 'baz' => 'exif' ), 'exif' );
00103 
00104                 $actual = $merger->getMetadataArray();
00105                 $expected = array(
00106                         'foo' => 'xmp',
00107                         'bar' => 'iptc (bad hash)',
00108                         'baz' => 'exif',
00109                         'fred' => 'xmp',
00110                 );
00111                 $this->assertEquals( $expected, $actual );
00112         }
00113 
00114         public function testPNGXMP() {
00115                 if ( !wfDl( 'xml' ) ) {
00116                         $this->markTestSkipped( "This test needs the xml extension." );
00117                 }
00118                 $handler = new BitmapMetadataHandler();
00119                 $result = $handler->png( $this->filePath . 'xmp.png' );
00120                 $expected = array (
00121                         'frameCount' => 0,
00122                         'loopCount' => 1,
00123                         'duration' => 0,
00124                         'bitDepth' => 1,
00125                         'colorType' => 'index-coloured',
00126                         'metadata' => array (
00127                                 'SerialNumber' => '123456789',
00128                                 '_MW_PNG_VERSION' => 1,
00129                         ),
00130                 );
00131                 $this->assertEquals( $expected, $result ); 
00132         }
00133         public function testPNGNative() {
00134                 $handler = new BitmapMetadataHandler();
00135                 $result = $handler->png( $this->filePath . 'Png-native-test.png' );
00136                 $expected = 'http://example.com/url';
00137                 $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] ); 
00138         }
00139         public function testTiffByteOrder() {
00140                 $handler = new BitmapMetadataHandler();
00141                 $res = $handler->getTiffByteOrder( $this->filePath . 'test.tiff' );
00142                 $this->assertEquals( 'LE', $res );
00143         }
00144 
00145 }