MediaWiki  REL1_20
BitmapMetadataHandlerTest.php
Go to the documentation of this file.
00001 <?php
00002 class BitmapMetadataHandlerTest extends MediaWikiTestCase {
00003 
00004         public function setUp() {
00005                 $this->filePath = __DIR__ . '/../../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         }
00080         public function testIPTCDatesInvalid() {
00081                 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00082                         'iptc-timetest-invalid.jpg' );
00083 
00084                 $this->assertEquals( '1845:03:02 00:01:02', $meta['DateTimeOriginal'] );
00085                 $this->assertFalse( isset( $meta['DateTimeDigitized'] ) );
00086         }
00087 
00093         public function testMerging() {
00094                 $merger = new BitmapMetadataHandler();
00095                 $merger->addMetadata( array( 'foo' => 'xmp' ), 'xmp-general' );
00096                 $merger->addMetadata( array( 'bar' => 'xmp' ), 'xmp-general' );
00097                 $merger->addMetadata( array( 'baz' => 'xmp' ), 'xmp-general' );
00098                 $merger->addMetadata( array( 'fred' => 'xmp' ), 'xmp-general' );
00099                 $merger->addMetadata( array( 'foo' => 'iptc (hash)' ), 'iptc-good-hash' );
00100                 $merger->addMetadata( array( 'bar' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
00101                 $merger->addMetadata( array( 'baz' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
00102                 $merger->addMetadata( array( 'fred' => 'iptc (no hash)' ), 'iptc-no-hash' );
00103                 $merger->addMetadata( array( 'baz' => 'exif' ), 'exif' );
00104 
00105                 $actual = $merger->getMetadataArray();
00106                 $expected = array(
00107                         'foo' => 'xmp',
00108                         'bar' => 'iptc (bad hash)',
00109                         'baz' => 'exif',
00110                         'fred' => 'xmp',
00111                 );
00112                 $this->assertEquals( $expected, $actual );
00113         }
00114 
00115         public function testPNGXMP() {
00116                 if ( !wfDl( 'xml' ) ) {
00117                         $this->markTestSkipped( "This test needs the xml extension." );
00118                 }
00119                 $handler = new BitmapMetadataHandler();
00120                 $result = $handler->png( $this->filePath . 'xmp.png' );
00121                 $expected = array (
00122                         'frameCount' => 0,
00123                         'loopCount' => 1,
00124                         'duration' => 0,
00125                         'bitDepth' => 1,
00126                         'colorType' => 'index-coloured',
00127                         'metadata' => array (
00128                                 'SerialNumber' => '123456789',
00129                                 '_MW_PNG_VERSION' => 1,
00130                         ),
00131                 );
00132                 $this->assertEquals( $expected, $result ); 
00133         }
00134         public function testPNGNative() {
00135                 $handler = new BitmapMetadataHandler();
00136                 $result = $handler->png( $this->filePath . 'Png-native-test.png' );
00137                 $expected = 'http://example.com/url';
00138                 $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] ); 
00139         }
00140         public function testTiffByteOrder() {
00141                 $handler = new BitmapMetadataHandler();
00142                 $res = $handler->getTiffByteOrder( $this->filePath . 'test.tiff' );
00143                 $this->assertEquals( 'LE', $res );
00144         }
00145 
00146 }