MediaWiki
REL1_21
|
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 00020 public function testMultilingualCascade() { 00021 global $wgShowEXIF; 00022 00023 if ( !wfDl( 'exif' ) ) { 00024 $this->markTestSkipped( "This test needs the exif extension." ); 00025 } 00026 if ( !wfDl( 'xml' ) ) { 00027 $this->markTestSkipped( "This test needs the xml extension." ); 00028 } 00029 00030 $wgShowEXIF = true; 00031 00032 $meta = BitmapMetadataHandler::Jpeg( $this->filePath . 00033 '/Xmp-exif-multilingual_test.jpg' ); 00034 00035 $expected = array( 00036 'x-default' => 'right(iptc)', 00037 'en' => 'right translation', 00038 '_type' => 'lang' 00039 ); 00040 00041 $this->assertArrayHasKey( 'ImageDescription', $meta, 00042 'Did not extract any ImageDescription info?!' ); 00043 00044 $this->assertEquals( $expected, $meta['ImageDescription'] ); 00045 } 00046 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 00066 public function testBadIPTC() { 00067 $meta = BitmapMetadataHandler::Jpeg( $this->filePath . 00068 'iptc-invalid-psir.jpg' ); 00069 $this->assertEquals( 'Created with GIMP', $meta['JPEGFileComment'][0] ); 00070 } 00071 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 00084 public function testIPTCDatesInvalid() { 00085 $meta = BitmapMetadataHandler::Jpeg( $this->filePath . 00086 'iptc-timetest-invalid.jpg' ); 00087 00088 $this->assertEquals( '1845:03:02 00:01:02', $meta['DateTimeOriginal'] ); 00089 $this->assertFalse( isset( $meta['DateTimeDigitized'] ) ); 00090 } 00091 00097 public function testMerging() { 00098 $merger = new BitmapMetadataHandler(); 00099 $merger->addMetadata( array( 'foo' => 'xmp' ), 'xmp-general' ); 00100 $merger->addMetadata( array( 'bar' => 'xmp' ), 'xmp-general' ); 00101 $merger->addMetadata( array( 'baz' => 'xmp' ), 'xmp-general' ); 00102 $merger->addMetadata( array( 'fred' => 'xmp' ), 'xmp-general' ); 00103 $merger->addMetadata( array( 'foo' => 'iptc (hash)' ), 'iptc-good-hash' ); 00104 $merger->addMetadata( array( 'bar' => 'iptc (bad hash)' ), 'iptc-bad-hash' ); 00105 $merger->addMetadata( array( 'baz' => 'iptc (bad hash)' ), 'iptc-bad-hash' ); 00106 $merger->addMetadata( array( 'fred' => 'iptc (no hash)' ), 'iptc-no-hash' ); 00107 $merger->addMetadata( array( 'baz' => 'exif' ), 'exif' ); 00108 00109 $actual = $merger->getMetadataArray(); 00110 $expected = array( 00111 'foo' => 'xmp', 00112 'bar' => 'iptc (bad hash)', 00113 'baz' => 'exif', 00114 'fred' => 'xmp', 00115 ); 00116 $this->assertEquals( $expected, $actual ); 00117 } 00118 00119 public function testPNGXMP() { 00120 if ( !wfDl( 'xml' ) ) { 00121 $this->markTestSkipped( "This test needs the xml extension." ); 00122 } 00123 $handler = new BitmapMetadataHandler(); 00124 $result = $handler->png( $this->filePath . 'xmp.png' ); 00125 $expected = array( 00126 'frameCount' => 0, 00127 'loopCount' => 1, 00128 'duration' => 0, 00129 'bitDepth' => 1, 00130 'colorType' => 'index-coloured', 00131 'metadata' => array( 00132 'SerialNumber' => '123456789', 00133 '_MW_PNG_VERSION' => 1, 00134 ), 00135 ); 00136 $this->assertEquals( $expected, $result ); 00137 } 00138 00139 public function testPNGNative() { 00140 $handler = new BitmapMetadataHandler(); 00141 $result = $handler->png( $this->filePath . 'Png-native-test.png' ); 00142 $expected = 'http://example.com/url'; 00143 $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] ); 00144 } 00145 00146 public function testTiffByteOrder() { 00147 $handler = new BitmapMetadataHandler(); 00148 $res = $handler->getTiffByteOrder( $this->filePath . 'test.tiff' ); 00149 $this->assertEquals( 'LE', $res ); 00150 } 00151 00152 }