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