MediaWiki
REL1_23
|
00001 <?php 00011 class JpegMetadataExtractorTest extends MediaWikiTestCase { 00012 00013 protected $filePath; 00014 00015 protected function setUp() { 00016 parent::setUp(); 00017 00018 $this->filePath = __DIR__ . '/../../data/media/'; 00019 } 00020 00029 public function testUtf8Comment( $file ) { 00030 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file ); 00031 $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] ); 00032 } 00033 00034 public static function provideUtf8Comment() { 00035 return array( 00036 array( 'jpeg-comment-utf.jpg' ), 00037 array( 'jpeg-padding-even.jpg' ), 00038 array( 'jpeg-padding-odd.jpg' ), 00039 ); 00040 } 00041 00043 public function testIso88591Comment() { 00044 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' ); 00045 $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] ); 00046 } 00047 00052 public function testBinaryCommentStripped() { 00053 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' ); 00054 $this->assertEmpty( $res['COM'] ); 00055 } 00056 00057 /* Very rarely a file can have multiple comments. 00058 * Order of comments is based on order inside the file. 00059 */ 00060 public function testMultipleComment() { 00061 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' ); 00062 $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] ); 00063 } 00064 00065 public function testXMPExtraction() { 00066 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00067 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' ); 00068 $this->assertEquals( $expected, $res['XMP'] ); 00069 } 00070 00071 public function testPSIRExtraction() { 00072 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00073 $expected = '50686f746f73686f7020332e30003842494d04040000000000181c02190004746573741c02190003666f6f1c020000020004'; 00074 $this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) ); 00075 } 00076 00077 public function testXMPExtractionAltAppId() { 00078 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-alt.jpg' ); 00079 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' ); 00080 $this->assertEquals( $expected, $res['XMP'] ); 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 }