MediaWiki
REL1_32
JpegMetadataExtractorTest.php
Go to the documentation of this file.
1
<?php
12
class
JpegMetadataExtractorTest
extends
MediaWikiTestCase
{
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
testXMPExtractionNullChar
() {
80
$res
=
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'jpeg-xmp-nullchar.jpg'
);
81
$expected = file_get_contents( $this->filePath .
'jpeg-xmp-psir.xmp'
);
82
$this->assertEquals( $expected,
$res
[
'XMP'
] );
83
}
84
85
public
function
testXMPExtractionAltAppId
() {
86
$res
=
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'jpeg-xmp-alt.jpg'
);
87
$expected = file_get_contents( $this->filePath .
'jpeg-xmp-psir.xmp'
);
88
$this->assertEquals( $expected,
$res
[
'XMP'
] );
89
}
90
91
public
function
testIPTCHashComparisionNoHash
() {
92
$segments =
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'jpeg-xmp-psir.jpg'
);
93
$res
=
JpegMetadataExtractor::doPSIR
( $segments[
'PSIR'
][0] );
94
95
$this->assertEquals(
'iptc-no-hash'
,
$res
);
96
}
97
98
public
function
testIPTCHashComparisionBadHash
() {
99
$segments =
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'jpeg-iptc-bad-hash.jpg'
);
100
$res
=
JpegMetadataExtractor::doPSIR
( $segments[
'PSIR'
][0] );
101
102
$this->assertEquals(
'iptc-bad-hash'
,
$res
);
103
}
104
105
public
function
testIPTCHashComparisionGoodHash
() {
106
$segments =
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'jpeg-iptc-good-hash.jpg'
);
107
$res
=
JpegMetadataExtractor::doPSIR
( $segments[
'PSIR'
][0] );
108
109
$this->assertEquals(
'iptc-good-hash'
,
$res
);
110
}
111
112
public
function
testExifByteOrder
() {
113
$res
=
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'exif-user-comment.jpg'
);
114
$expected =
'BE'
;
115
$this->assertEquals( $expected,
$res
[
'byteOrder'
] );
116
}
117
118
public
function
testInfiniteRead
() {
119
// test file truncated right after a segment, which previously
120
// caused an infinite loop looking for the next segment byte.
121
// Should get past infinite loop and throw in wfUnpack()
122
$this->setExpectedException(
'MWException'
);
123
$res
=
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'jpeg-segment-loop1.jpg'
);
124
}
125
126
public
function
testInfiniteRead2
() {
127
// test file truncated after a segment's marker and size, which
128
// would cause a seek past end of file. Seek past end of file
129
// doesn't actually fail, but prevents further reading and was
130
// devolving into the previous case (testInfiniteRead).
131
$this->setExpectedException(
'MWException'
);
132
$res
=
JpegMetadataExtractor::segmentSplitter
( $this->filePath .
'jpeg-segment-loop2.jpg'
);
133
}
134
}
JpegMetadataExtractorTest
Definition
JpegMetadataExtractorTest.php:12
JpegMetadataExtractorTest\testIPTCHashComparisionGoodHash
testIPTCHashComparisionGoodHash()
Definition
JpegMetadataExtractorTest.php:105
JpegMetadataExtractorTest\testInfiniteRead2
testInfiniteRead2()
Definition
JpegMetadataExtractorTest.php:126
JpegMetadataExtractorTest\testIso88591Comment
testIso88591Comment()
The file is iso-8859-1, but it should get auto converted.
Definition
JpegMetadataExtractorTest.php:44
JpegMetadataExtractorTest\testExifByteOrder
testExifByteOrder()
Definition
JpegMetadataExtractorTest.php:112
JpegMetadataExtractorTest\testIPTCHashComparisionBadHash
testIPTCHashComparisionBadHash()
Definition
JpegMetadataExtractorTest.php:98
JpegMetadataExtractorTest\setUp
setUp()
Definition
JpegMetadataExtractorTest.php:16
JpegMetadataExtractorTest\testXMPExtraction
testXMPExtraction()
Definition
JpegMetadataExtractorTest.php:66
JpegMetadataExtractorTest\testMultipleComment
testMultipleComment()
Definition
JpegMetadataExtractorTest.php:61
JpegMetadataExtractorTest\testIPTCHashComparisionNoHash
testIPTCHashComparisionNoHash()
Definition
JpegMetadataExtractorTest.php:91
JpegMetadataExtractorTest\testUtf8Comment
testUtf8Comment( $file)
We also use this test to test padding bytes don't screw stuff up.
Definition
JpegMetadataExtractorTest.php:30
JpegMetadataExtractorTest\testBinaryCommentStripped
testBinaryCommentStripped()
Comment values that are non-textual (random binary junk) should not be shown.
Definition
JpegMetadataExtractorTest.php:53
JpegMetadataExtractorTest\testXMPExtractionNullChar
testXMPExtractionNullChar()
Definition
JpegMetadataExtractorTest.php:79
JpegMetadataExtractorTest\testXMPExtractionAltAppId
testXMPExtractionAltAppId()
Definition
JpegMetadataExtractorTest.php:85
JpegMetadataExtractorTest\$filePath
$filePath
Definition
JpegMetadataExtractorTest.php:14
JpegMetadataExtractorTest\testInfiniteRead
testInfiniteRead()
Definition
JpegMetadataExtractorTest.php:118
JpegMetadataExtractorTest\provideUtf8Comment
static provideUtf8Comment()
Definition
JpegMetadataExtractorTest.php:35
JpegMetadataExtractorTest\testPSIRExtraction
testPSIRExtraction()
Definition
JpegMetadataExtractorTest.php:72
JpegMetadataExtractor\doPSIR
static doPSIR( $app13)
This reads the photoshop image resource.
Definition
JpegMetadataExtractor.php:212
JpegMetadataExtractor\segmentSplitter
static segmentSplitter( $filename)
Function to extract metadata segments of interest from jpeg files based on GIFMetadataExtractor.
Definition
JpegMetadataExtractor.php:52
MediaWikiTestCase
Definition
MediaWikiTestCase.php:16
$res
$res
Definition
database.txt:21
tests
phpunit
includes
media
JpegMetadataExtractorTest.php
Generated on Mon Nov 25 2024 15:58:46 for MediaWiki by
1.10.0