MediaWiki  1.23.15
JpegMetadataExtractorTest.php
Go to the documentation of this file.
1 <?php
12 
13  protected $filePath;
14 
15  protected function setUp() {
16  parent::setUp();
17 
18  $this->filePath = __DIR__ . '/../../data/media/';
19  }
20 
29  public function testUtf8Comment( $file ) {
30  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file );
31  $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] );
32  }
33 
34  public static function provideUtf8Comment() {
35  return array(
36  array( 'jpeg-comment-utf.jpg' ),
37  array( 'jpeg-padding-even.jpg' ),
38  array( 'jpeg-padding-odd.jpg' ),
39  );
40  }
41 
43  public function testIso88591Comment() {
44  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' );
45  $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] );
46  }
47 
52  public function testBinaryCommentStripped() {
53  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' );
54  $this->assertEmpty( $res['COM'] );
55  }
56 
57  /* Very rarely a file can have multiple comments.
58  * Order of comments is based on order inside the file.
59  */
60  public function testMultipleComment() {
61  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' );
62  $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] );
63  }
64 
65  public function testXMPExtraction() {
66  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
67  $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' );
68  $this->assertEquals( $expected, $res['XMP'] );
69  }
70 
71  public function testPSIRExtraction() {
72  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
73  $expected = '50686f746f73686f7020332e30003842494d04040000000000181c02190004746573741c02190003666f6f1c020000020004';
74  $this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) );
75  }
76 
77  public function testXMPExtractionAltAppId() {
78  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-alt.jpg' );
79  $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' );
80  $this->assertEquals( $expected, $res['XMP'] );
81  }
82 
83  public function testIPTCHashComparisionNoHash() {
84  $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
85  $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
86 
87  $this->assertEquals( 'iptc-no-hash', $res );
88  }
89 
90  public function testIPTCHashComparisionBadHash() {
91  $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-bad-hash.jpg' );
92  $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
93 
94  $this->assertEquals( 'iptc-bad-hash', $res );
95  }
96 
97  public function testIPTCHashComparisionGoodHash() {
98  $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-good-hash.jpg' );
99  $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] );
100 
101  $this->assertEquals( 'iptc-good-hash', $res );
102  }
103 
104  public function testExifByteOrder() {
105  $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'exif-user-comment.jpg' );
106  $expected = 'BE';
107  $this->assertEquals( $expected, $res['byteOrder'] );
108  }
109 }
JpegMetadataExtractorTest\testXMPExtraction
testXMPExtraction()
Definition: JpegMetadataExtractorTest.php:65
JpegMetadataExtractorTest\testXMPExtractionAltAppId
testXMPExtractionAltAppId()
Definition: JpegMetadataExtractorTest.php:77
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
JpegMetadataExtractorTest\testIso88591Comment
testIso88591Comment()
The file is iso-8859-1, but it should get auto converted.
Definition: JpegMetadataExtractorTest.php:43
JpegMetadataExtractorTest\testIPTCHashComparisionBadHash
testIPTCHashComparisionBadHash()
Definition: JpegMetadataExtractorTest.php:90
JpegMetadataExtractorTest\testIPTCHashComparisionNoHash
testIPTCHashComparisionNoHash()
Definition: JpegMetadataExtractorTest.php:83
JpegMetadataExtractorTest\setUp
setUp()
Definition: JpegMetadataExtractorTest.php:15
JpegMetadataExtractorTest
Definition: JpegMetadataExtractorTest.php:11
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
JpegMetadataExtractor\doPSIR
static doPSIR( $app13)
This reads the photoshop image resource.
Definition: JpegMetadataExtractor.php:201
JpegMetadataExtractorTest\testUtf8Comment
testUtf8Comment( $file)
We also use this test to test padding bytes don't screw stuff up.
Definition: JpegMetadataExtractorTest.php:29
JpegMetadataExtractorTest\testPSIRExtraction
testPSIRExtraction()
Definition: JpegMetadataExtractorTest.php:71
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
JpegMetadataExtractorTest\testIPTCHashComparisionGoodHash
testIPTCHashComparisionGoodHash()
Definition: JpegMetadataExtractorTest.php:97
JpegMetadataExtractor\segmentSplitter
static segmentSplitter( $filename)
Function to extract metadata segments of interest from jpeg files based on GIFMetadataExtractor.
Definition: JpegMetadataExtractor.php:50
JpegMetadataExtractorTest\testMultipleComment
testMultipleComment()
Definition: JpegMetadataExtractorTest.php:60
JpegMetadataExtractorTest\testExifByteOrder
testExifByteOrder()
Definition: JpegMetadataExtractorTest.php:104
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
JpegMetadataExtractorTest\provideUtf8Comment
static provideUtf8Comment()
Definition: JpegMetadataExtractorTest.php:34
JpegMetadataExtractorTest\$filePath
$filePath
Definition: JpegMetadataExtractorTest.php:13
JpegMetadataExtractorTest\testBinaryCommentStripped
testBinaryCommentStripped()
Comment values that are non-textual (random binary junk) should not be shown.
Definition: JpegMetadataExtractorTest.php:52
$res
$res
Definition: database.txt:21