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