MediaWiki REL1_32
BitmapMetadataHandlerTest.php
Go to the documentation of this file.
1<?php
2
7
8 protected function setUp() {
9 parent::setUp();
10
11 $this->setMwGlobals( 'wgShowEXIF', false );
12
13 $this->filePath = __DIR__ . '/../../data/media/';
14 }
15
25 public function testMultilingualCascade() {
26 $this->checkPHPExtension( 'exif' );
27 $this->checkPHPExtension( 'xml' );
28
29 $this->setMwGlobals( 'wgShowEXIF', true );
30
31 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
32 '/Xmp-exif-multilingual_test.jpg' );
33
34 $expected = [
35 'x-default' => 'right(iptc)',
36 'en' => 'right translation',
37 '_type' => 'lang'
38 ];
39
40 $this->assertArrayHasKey( 'ImageDescription', $meta,
41 'Did not extract any ImageDescription info?!' );
42
43 $this->assertEquals( $expected, $meta['ImageDescription'] );
44 }
45
54 public function testJpegComment() {
55 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
56 'jpeg-comment-utf.jpg' );
57
58 $this->assertEquals( 'UTF-8 JPEG Comment — ¼',
59 $meta['JPEGFileComment'][0] );
60 }
61
67 public function testBadIPTC() {
68 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
69 'iptc-invalid-psir.jpg' );
70 $this->assertEquals( 'Created with GIMP', $meta['JPEGFileComment'][0] );
71 }
72
76 public function testIPTCDates() {
77 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
78 'iptc-timetest.jpg' );
79
80 $this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] );
81 $this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] );
82 }
83
89 public function testIPTCDatesInvalid() {
90 $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
91 'iptc-timetest-invalid.jpg' );
92
93 $this->assertEquals( '1845:03:02 00:01:02', $meta['DateTimeOriginal'] );
94 $this->assertFalse( isset( $meta['DateTimeDigitized'] ) );
95 }
96
104 public function testMerging() {
105 $merger = new BitmapMetadataHandler();
106 $merger->addMetadata( [ 'foo' => 'xmp' ], 'xmp-general' );
107 $merger->addMetadata( [ 'bar' => 'xmp' ], 'xmp-general' );
108 $merger->addMetadata( [ 'baz' => 'xmp' ], 'xmp-general' );
109 $merger->addMetadata( [ 'fred' => 'xmp' ], 'xmp-general' );
110 $merger->addMetadata( [ 'foo' => 'iptc (hash)' ], 'iptc-good-hash' );
111 $merger->addMetadata( [ 'bar' => 'iptc (bad hash)' ], 'iptc-bad-hash' );
112 $merger->addMetadata( [ 'baz' => 'iptc (bad hash)' ], 'iptc-bad-hash' );
113 $merger->addMetadata( [ 'fred' => 'iptc (no hash)' ], 'iptc-no-hash' );
114 $merger->addMetadata( [ 'baz' => 'exif' ], 'exif' );
115
116 $actual = $merger->getMetadataArray();
117 $expected = [
118 'foo' => 'xmp',
119 'bar' => 'iptc (bad hash)',
120 'baz' => 'exif',
121 'fred' => 'xmp',
122 ];
123 $this->assertEquals( $expected, $actual );
124 }
125
129 public function testPNGXMP() {
130 $this->checkPHPExtension( 'xml' );
131
133 $result = $handler->PNG( $this->filePath . 'xmp.png' );
134 $expected = [
135 'frameCount' => 0,
136 'loopCount' => 1,
137 'duration' => 0,
138 'bitDepth' => 1,
139 'colorType' => 'index-coloured',
140 'metadata' => [
141 'SerialNumber' => '123456789',
142 '_MW_PNG_VERSION' => 1,
143 ],
144 ];
145 $this->assertEquals( $expected, $result );
146 }
147
151 public function testPNGNative() {
153 $result = $handler->PNG( $this->filePath . 'Png-native-test.png' );
154 $expected = 'http://example.com/url';
155 $this->assertEquals( $expected, $result['metadata']['Identifier']['x-default'] );
156 }
157
161 public function testTiffByteOrder() {
163 $res = $handler->getTiffByteOrder( $this->filePath . 'test.tiff' );
164 $this->assertEquals( 'LE', $res );
165 }
166}
testBadIPTC()
Make sure a bad iptc block doesn't stop the other metadata from being extracted.
testJpegComment()
Test for jpeg comments are being handled by BitmapMetadataHandler correctly.
testMultilingualCascade()
Test if having conflicting metadata values from different types of metadata, that the right one takes...
testIPTCDatesInvalid()
File has an invalid time (+ one valid but really weird time) that shouldn't be included BitmapMetadat...
testIPTCDates()
BitmapMetadataHandler::Jpeg.
testMerging()
XMP data should take priority over iptc data when hash has been updated, but not when the hash is wro...
testPNGXMP()
BitmapMetadataHandler::png.
testPNGNative()
BitmapMetadataHandler::png.
testTiffByteOrder()
BitmapMetadataHandler::getTiffByteOrder.
Class to deal with reconciling and extracting metadata from bitmap images.
static Jpeg( $filename)
Main entry point for jpeg's.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
$res
Definition database.txt:21
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition hooks.txt:933