MediaWiki
REL1_23
|
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 $this->checkPHPExtension( 'exif' ); 00023 $this->checkPHPExtension( 'xml' ); 00024 00025 $this->setMwGlobals( '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 00050 public function testJpegComment() { 00051 $meta = BitmapMetadataHandler::Jpeg( $this->filePath . 00052 'jpeg-comment-utf.jpg' ); 00053 00054 $this->assertEquals( 'UTF-8 JPEG Comment — ¼', 00055 $meta['JPEGFileComment'][0] ); 00056 } 00057 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 00072 public function testIPTCDates() { 00073 $meta = BitmapMetadataHandler::Jpeg( $this->filePath . 00074 'iptc-timetest.jpg' ); 00075 00076 $this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] ); 00077 $this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] ); 00078 } 00079 00085 public function testIPTCDatesInvalid() { 00086 $meta = BitmapMetadataHandler::Jpeg( $this->filePath . 00087 'iptc-timetest-invalid.jpg' ); 00088 00089 $this->assertEquals( '1845:03:02 00:01:02', $meta['DateTimeOriginal'] ); 00090 $this->assertFalse( isset( $meta['DateTimeDigitized'] ) ); 00091 } 00092 00100 public function testMerging() { 00101 $merger = new BitmapMetadataHandler(); 00102 $merger->addMetadata( array( 'foo' => 'xmp' ), 'xmp-general' ); 00103 $merger->addMetadata( array( 'bar' => 'xmp' ), 'xmp-general' ); 00104 $merger->addMetadata( array( 'baz' => 'xmp' ), 'xmp-general' ); 00105 $merger->addMetadata( array( 'fred' => 'xmp' ), 'xmp-general' ); 00106 $merger->addMetadata( array( 'foo' => 'iptc (hash)' ), 'iptc-good-hash' ); 00107 $merger->addMetadata( array( 'bar' => 'iptc (bad hash)' ), 'iptc-bad-hash' ); 00108 $merger->addMetadata( array( 'baz' => 'iptc (bad hash)' ), 'iptc-bad-hash' ); 00109 $merger->addMetadata( array( 'fred' => 'iptc (no hash)' ), 'iptc-no-hash' ); 00110 $merger->addMetadata( array( 'baz' => 'exif' ), 'exif' ); 00111 00112 $actual = $merger->getMetadataArray(); 00113 $expected = array( 00114 'foo' => 'xmp', 00115 'bar' => 'iptc (bad hash)', 00116 'baz' => 'exif', 00117 'fred' => 'xmp', 00118 ); 00119 $this->assertEquals( $expected, $actual ); 00120 } 00121 00125 public function testPNGXMP() { 00126 if ( !extension_loaded( 'xml' ) ) { 00127 $this->markTestSkipped( "This test needs the xml extension." ); 00128 } 00129 $handler = new BitmapMetadataHandler(); 00130 $result = $handler->png( $this->filePath . 'xmp.png' ); 00131 $expected = array( 00132 'frameCount' => 0, 00133 'loopCount' => 1, 00134 'duration' => 0, 00135 'bitDepth' => 1, 00136 'colorType' => 'index-coloured', 00137 'metadata' => array( 00138 'SerialNumber' => '123456789', 00139 '_MW_PNG_VERSION' => 1, 00140 ), 00141 ); 00142 $this->assertEquals( $expected, $result ); 00143 } 00144 00148 public function testPNGNative() { 00149 $handler = new BitmapMetadataHandler(); 00150 $result = $handler->png( $this->filePath . 'Png-native-test.png' ); 00151 $expected = 'http://example.com/url'; 00152 $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] ); 00153 } 00154 00158 public function testTiffByteOrder() { 00159 $handler = new BitmapMetadataHandler(); 00160 $res = $handler->getTiffByteOrder( $this->filePath . 'test.tiff' ); 00161 $this->assertEquals( 'LE', $res ); 00162 } 00163 }