MediaWiki
REL1_21
|
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 00030 public static function provideUtf8Comment() { 00031 return array( 00032 array( 'jpeg-comment-utf.jpg' ), 00033 array( 'jpeg-padding-even.jpg' ), 00034 array( 'jpeg-padding-odd.jpg' ), 00035 ); 00036 } 00037 00039 public function testIso88591Comment() { 00040 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' ); 00041 $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] ); 00042 } 00043 00048 public function testBinaryCommentStripped() { 00049 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' ); 00050 $this->assertEmpty( $res['COM'] ); 00051 } 00052 00053 /* Very rarely a file can have multiple comments. 00054 * Order of comments is based on order inside the file. 00055 */ 00056 public function testMultipleComment() { 00057 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' ); 00058 $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] ); 00059 } 00060 00061 public function testXMPExtraction() { 00062 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00063 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' ); 00064 $this->assertEquals( $expected, $res['XMP'] ); 00065 } 00066 00067 public function testPSIRExtraction() { 00068 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00069 $expected = '50686f746f73686f7020332e30003842494d04040000000000181c02190004746573741c02190003666f6f1c020000020004'; 00070 $this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) ); 00071 } 00072 00073 public function testXMPExtractionAltAppId() { 00074 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-alt.jpg' ); 00075 $expected = file_get_contents( $this->filePath . 'jpeg-xmp-psir.xmp' ); 00076 $this->assertEquals( $expected, $res['XMP'] ); 00077 } 00078 00079 00080 public function testIPTCHashComparisionNoHash() { 00081 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' ); 00082 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] ); 00083 00084 $this->assertEquals( 'iptc-no-hash', $res ); 00085 } 00086 00087 public function testIPTCHashComparisionBadHash() { 00088 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-bad-hash.jpg' ); 00089 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] ); 00090 00091 $this->assertEquals( 'iptc-bad-hash', $res ); 00092 } 00093 00094 public function testIPTCHashComparisionGoodHash() { 00095 $segments = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-iptc-good-hash.jpg' ); 00096 $res = JpegMetadataExtractor::doPSIR( $segments['PSIR'][0] ); 00097 00098 $this->assertEquals( 'iptc-good-hash', $res ); 00099 } 00100 00101 public function testExifByteOrder() { 00102 $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'exif-user-comment.jpg' ); 00103 $expected = 'BE'; 00104 $this->assertEquals( $expected, $res['byteOrder'] ); 00105 } 00106 }