2 class BitmapMetadataHandlerTest
extends MediaWikiTestCase
{
4 public function setUp() {
5 $this->filePath
= dirname( __FILE__
) . '/../../data/media/';
9 * Test if having conflicting metadata values from different
10 * types of metadata, that the right one takes precedence.
12 * Basically the file has IPTC and XMP metadata, the
13 * IPTC should override the XMP, except for the multilingual
14 * translation (to en) where XMP should win.
16 public function testMultilingualCascade() {
17 if ( !wfDl( 'exif' ) ) {
18 $this->markTestSkipped( "This test needs the exif extension." );
20 if ( !wfDl( 'xml' ) ) {
21 $this->markTestSkipped( "This test needs the xml extension." );
24 $oldExif = $wgShowEXIF;
27 $meta = BitmapMetadataHandler
::Jpeg( $this->filePath
.
28 '/Xmp-exif-multilingual_test.jpg' );
31 'x-default' => 'right(iptc)',
32 'en' => 'right translation',
36 $this->assertArrayHasKey( 'ImageDescription', $meta,
37 'Did not extract any ImageDescription info?!' );
39 $this->assertEquals( $expected, $meta['ImageDescription'] );
41 $wgShowEXIF = $oldExif;
45 * Test for jpeg comments are being handled by
46 * BitmapMetadataHandler correctly.
48 * There's more extensive tests of comment extraction in
49 * JpegMetadataExtractorTests.php
51 public function testJpegComment() {
52 $meta = BitmapMetadataHandler
::Jpeg( $this->filePath
.
53 'jpeg-comment-utf.jpg' );
55 $this->assertEquals( 'UTF-8 JPEG Comment — ¼',
56 $meta['JPEGFileComment'][0] );
59 public function testIPTCDates() {
60 $meta = BitmapMetadataHandler
::Jpeg( $this->filePath
.
61 'iptc-timetest.jpg' );
63 $this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] );
64 $this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] );
66 /* File has an invalid time (+ one valid but really weird time)
67 * that shouldn't be included
69 public function testIPTCDatesInvalid() {
70 $meta = BitmapMetadataHandler
::Jpeg( $this->filePath
.
71 'iptc-timetest-invalid.jpg' );
73 $this->assertEquals( '1845:03:02 00:01:02', $meta['DateTimeOriginal'] );
74 $this->assertFalse( isset( $meta['DateTimeDigitized'] ) );
78 * XMP data should take priority over iptc data
79 * when hash has been updated, but not when
82 public function testMerging() {
83 $merger = new BitmapMetadataHandler();
84 $merger->addMetadata( array( 'foo' => 'xmp' ), 'xmp-general' );
85 $merger->addMetadata( array( 'bar' => 'xmp' ), 'xmp-general' );
86 $merger->addMetadata( array( 'baz' => 'xmp' ), 'xmp-general' );
87 $merger->addMetadata( array( 'fred' => 'xmp' ), 'xmp-general' );
88 $merger->addMetadata( array( 'foo' => 'iptc (hash)' ), 'iptc-good-hash' );
89 $merger->addMetadata( array( 'bar' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
90 $merger->addMetadata( array( 'baz' => 'iptc (bad hash)' ), 'iptc-bad-hash' );
91 $merger->addMetadata( array( 'fred' => 'iptc (no hash)' ), 'iptc-no-hash' );
92 $merger->addMetadata( array( 'baz' => 'exif' ), 'exif' );
94 $actual = $merger->getMetadataArray();
97 'bar' => 'iptc (bad hash)',
101 $this->assertEquals( $expected, $actual );
104 public function testPNGXMP() {
105 if ( !wfDl( 'xml' ) ) {
106 $this->markTestSkipped( "This test needs the xml extension." );
108 $handler = new BitmapMetadataHandler();
109 $result = $handler->png( $this->filePath
. 'xmp.png' );
115 'colorType' => 'index-coloured',
116 'metadata' => array (
117 'SerialNumber' => '123456789',
118 '_MW_PNG_VERSION' => 1,
121 $this->assertEquals( $expected, $result );
123 public function testPNGNative() {
124 $handler = new BitmapMetadataHandler();
125 $result = $handler->png( $this->filePath
. 'Png-native-test.png' );
126 $expected = 'http://example.com/url';
127 $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] );
129 public function testTiffByteOrder() {
130 $handler = new BitmapMetadataHandler();
131 $res = $handler->getTiffByteOrder( $this->filePath
. 'test.tiff' );
132 $this->assertEquals( 'LE', $res );