MediaWiki  REL1_22
BitmapMetadataHandlerTest.php
Go to the documentation of this file.
00001 <?php
00002 class BitmapMetadataHandlerTest extends MediaWikiTestCase {
00003 
00004     protected function setUp() {
00005         parent::setUp();
00006 
00007         $this->setMwGlobals( 'wgShowEXIF', false );
00008 
00009         $this->filePath = __DIR__ . '/../../data/media/';
00010     }
00011 
00021     public function testMultilingualCascade() {
00022         if ( !extension_loaded( 'exif' ) ) {
00023             $this->markTestSkipped( "This test needs the exif extension." );
00024         }
00025         if ( !extension_loaded( 'xml' ) ) {
00026             $this->markTestSkipped( "This test needs the xml extension." );
00027         }
00028 
00029         $this->setMwGlobals( 'wgShowEXIF', true );
00030 
00031         $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00032             '/Xmp-exif-multilingual_test.jpg' );
00033 
00034         $expected = array(
00035             'x-default' => 'right(iptc)',
00036             'en' => 'right translation',
00037             '_type' => 'lang'
00038         );
00039 
00040         $this->assertArrayHasKey( 'ImageDescription', $meta,
00041             'Did not extract any ImageDescription info?!' );
00042 
00043         $this->assertEquals( $expected, $meta['ImageDescription'] );
00044     }
00045 
00054     public function testJpegComment() {
00055         $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00056             'jpeg-comment-utf.jpg' );
00057 
00058         $this->assertEquals( 'UTF-8 JPEG Comment — ¼',
00059             $meta['JPEGFileComment'][0] );
00060     }
00061 
00067     public function testBadIPTC() {
00068         $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00069             'iptc-invalid-psir.jpg' );
00070         $this->assertEquals( 'Created with GIMP', $meta['JPEGFileComment'][0] );
00071     }
00072 
00076     public function testIPTCDates() {
00077         $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00078             'iptc-timetest.jpg' );
00079 
00080         $this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] );
00081         $this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] );
00082     }
00083 
00089     public function testIPTCDatesInvalid() {
00090         $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
00091             'iptc-timetest-invalid.jpg' );
00092 
00093         $this->assertEquals( '1845:03:02 00:01:02', $meta['DateTimeOriginal'] );
00094         $this->assertFalse( isset( $meta['DateTimeDigitized'] ) );
00095     }
00096 
00104     public function testMerging() {
00105         $merger = new BitmapMetadataHandler();
00106         $merger->addMetadata( array( 'foo' => 'xmp' ), 'xmp-general' );
00107         $merger->addMetadata( array( 'bar' => 'xmp' ), 'xmp-general' );
00108         $merger->addMetadata( array( 'baz' => 'xmp' ), 'xmp-general' );
00109         $merger->addMetadata( array( 'fred' => 'xmp' ), 'xmp-general' );
00110         $merger->addMetadata( array( 'foo' => 'iptc (hash)' ), 'iptc-good-hash' );
00111         $merger->addMetadata( array( 'bar' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
00112         $merger->addMetadata( array( 'baz' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
00113         $merger->addMetadata( array( 'fred' => 'iptc (no hash)' ), 'iptc-no-hash' );
00114         $merger->addMetadata( array( 'baz' => 'exif' ), 'exif' );
00115 
00116         $actual = $merger->getMetadataArray();
00117         $expected = array(
00118             'foo' => 'xmp',
00119             'bar' => 'iptc (bad hash)',
00120             'baz' => 'exif',
00121             'fred' => 'xmp',
00122         );
00123         $this->assertEquals( $expected, $actual );
00124     }
00125 
00129     public function testPNGXMP() {
00130         if ( !extension_loaded( 'xml' ) ) {
00131             $this->markTestSkipped( "This test needs the xml extension." );
00132         }
00133         $handler = new BitmapMetadataHandler();
00134         $result = $handler->png( $this->filePath . 'xmp.png' );
00135         $expected = array(
00136             'frameCount' => 0,
00137             'loopCount' => 1,
00138             'duration' => 0,
00139             'bitDepth' => 1,
00140             'colorType' => 'index-coloured',
00141             'metadata' => array(
00142                 'SerialNumber' => '123456789',
00143                 '_MW_PNG_VERSION' => 1,
00144             ),
00145         );
00146         $this->assertEquals( $expected, $result );
00147     }
00148 
00152     public function testPNGNative() {
00153         $handler = new BitmapMetadataHandler();
00154         $result = $handler->png( $this->filePath . 'Png-native-test.png' );
00155         $expected = 'http://example.com/url';
00156         $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] );
00157     }
00158 
00162     public function testTiffByteOrder() {
00163         $handler = new BitmapMetadataHandler();
00164         $res = $handler->getTiffByteOrder( $this->filePath . 'test.tiff' );
00165         $this->assertEquals( 'LE', $res );
00166     }
00167 }