MediaWiki REL1_28
JpegMetadataExtractorTest.php
Go to the documentation of this file.
1<?php
13
14 protected $filePath;
15
16 protected function setUp() {
17 parent::setUp();
18
19 $this->filePath = __DIR__ . '/../../data/media/';
20 }
21
30 public function testUtf8Comment( $file ) {
31 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file );
32 $this->assertEquals( [ 'UTF-8 JPEG Comment — ¼' ], $res['COM'] );
33 }
34
35 public static function provideUtf8Comment() {
36 return [
37 [ 'jpeg-comment-utf.jpg' ],
38 [ 'jpeg-padding-even.jpg' ],
39 [ 'jpeg-padding-odd.jpg' ],
40 ];
41 }
42
44 public function testIso88591Comment() {
45 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' );
46 $this->assertEquals( [ 'ISO-8859-1 JPEG Comment - ¼' ], $res['COM'] );
47 }
48
53 public function testBinaryCommentStripped() {
54 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' );
55 $this->assertEmpty( $res['COM'] );
56 }
57
58 /* Very rarely a file can have multiple comments.
59 * Order of comments is based on order inside the file.
60 */
61 public function testMultipleComment() {
62 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' );
63 $this->assertEquals( [ 'foo', 'bar' ], $res['COM'] );
64 }
65
66 public function testXMPExtraction() {
67 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
68 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' );
69 $this->assertEquals( $expected, $res['XMP'] );
70 }
71
72 public function testPSIRExtraction() {
73 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
74 $expected = '50686f746f73686f7020332e30003842494d04040000000'
75 . '000181c02190004746573741c02190003666f6f1c020000020004';
76 $this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) );
77 }
78
79 public function testXMPExtractionAltAppId() {
80 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-alt.jpg' );
81 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' );
82 $this->assertEquals( $expected, $res['XMP'] );
83 }
84
86 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
87 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
88
89 $this->assertEquals( 'iptc-no-hash', $res );
90 }
91
93 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-bad-hash.jpg' );
94 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
95
96 $this->assertEquals( 'iptc-bad-hash', $res );
97 }
98
100 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-good-hash.jpg' );
101 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
102
103 $this->assertEquals( 'iptc-good-hash', $res );
104 }
105
106 public function testExifByteOrder() {
107 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'exif-user-comment.jpg' );
108 $expected = 'BE';
109 $this->assertEquals( $expected, $res['byteOrder'] );
110 }
111}
testIso88591Comment()
The file is iso-8859-1, but it should get auto converted.
testUtf8Comment( $file)
We also use this test to test padding bytes don't screw stuff up.
testBinaryCommentStripped()
Comment values that are non-textual (random binary junk) should not be shown.
static doPSIR( $app13)
This reads the photoshop image resource.
static segmentSplitter( $filename)
Function to extract metadata segments of interest from jpeg files based on GIFMetadataExtractor.
$res
Definition database.txt:21
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37