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