MediaWiki
master
|
00001 <?php 00009 class JpegMetadataExtractorTest extends MediaWikiTestCase { 00010 00011 protected function setUp() { 00012 parent::setUp(); 00013 00014 $this->filePath = __DIR__ . '/../../data/media/'; 00015 } 00016 00025 public function testUtf8Comment( $file ) { 00026 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file ); 00027 $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] ); 00028 } 00029 public static function provideUtf8Comment() { 00030 return array( 00031 array( 'jpeg-comment-utf.jpg' ), 00032 array( 'jpeg-padding-even.jpg' ), 00033 array( 'jpeg-padding-odd.jpg' ), 00034 ); 00035 } 00037 public function testIso88591Comment() { 00038 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' ); 00039 $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] ); 00040 } 00045 public function testBinaryCommentStripped() { 00046 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' ); 00047 $this->assertEmpty( $res['COM'] ); 00048 } 00049 /* Very rarely a file can have multiple comments. 00050 * Order of comments is based on order inside the file. 00051 */ 00052 public function testMultipleComment() { 00053 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' ); 00054 $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] ); 00055 } 00056 public function testXMPExtraction() { 00057 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00058 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' ); 00059 $this->assertEquals( $expected, $res['XMP'] ); 00060 } 00061 public function testPSIRExtraction() { 00062 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00063 $expected = '50686f746f73686f7020332e30003842494d04040000000000181c02190004746573741c02190003666f6f1c020000020004'; 00064 $this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) ); 00065 } 00066 public function testXMPExtractionAltAppId() { 00067 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-alt.jpg' ); 00068 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' ); 00069 $this->assertEquals( $expected, $res['XMP'] ); 00070 } 00071 00072 00073 public function testIPTCHashComparisionNoHash() { 00074 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00075 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] ); 00076 00077 $this->assertEquals( 'iptc-no-hash', $res ); 00078 } 00079 public function testIPTCHashComparisionBadHash() { 00080 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-bad-hash.jpg' ); 00081 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] ); 00082 00083 $this->assertEquals( 'iptc-bad-hash', $res ); 00084 } 00085 public function testIPTCHashComparisionGoodHash() { 00086 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-good-hash.jpg' ); 00087 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] ); 00088 00089 $this->assertEquals( 'iptc-good-hash', $res ); 00090 } 00091 public function testExifByteOrder() { 00092 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'exif-user-comment.jpg' ); 00093 $expected = 'BE'; 00094 $this->assertEquals( $expected, $res['byteOrder'] ); 00095 } 00096 }