Index: trunk/phase3/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php |
— | — | @@ -32,4 +32,19 @@ |
33 | 33 | |
34 | 34 | $this->assertEquals( $expected, $meta['ImageDescription'] ); |
35 | 35 | } |
| 36 | + |
| 37 | + /** |
| 38 | + * Test for jpeg comments are being handled by |
| 39 | + * BitmapMetadataHandler correctly. |
| 40 | + * |
| 41 | + * There's more extensive tests of comment extraction in |
| 42 | + * JpegMetadataExtractorTests.php |
| 43 | + */ |
| 44 | + public function testJpegComment() { |
| 45 | + $meta = BitmapMetadataHandler::Jpeg( $this->filePath . |
| 46 | + 'jpeg-comment-utf.jpg' ); |
| 47 | + |
| 48 | + $this->assertEquals( 'UTF-8 JPEG Comment — ¼', |
| 49 | + $meta['JPEGFileComment'][0] ); |
| 50 | + } |
36 | 51 | } |
Index: trunk/phase3/tests/phpunit/includes/media/JpegMetadataExtractorTest.php |
— | — | @@ -0,0 +1,32 @@ |
| 2 | +<?php |
| 3 | +class JpegMetadataExtractorTest extends MediaWikiTestCase { |
| 4 | + |
| 5 | + public function setUp() { |
| 6 | + $this->filePath = dirname( __FILE__ ) . '/../../data/media/'; |
| 7 | + } |
| 8 | + |
| 9 | + public function testUtf8Comment() { |
| 10 | + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-utf.jpg' ); |
| 11 | + $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] ); |
| 12 | + } |
| 13 | + /** The file is iso-8859-1, but it should get auto converted */ |
| 14 | + public function testIso88591Comment() { |
| 15 | + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' ); |
| 16 | + $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] ); |
| 17 | + } |
| 18 | + /** Comment values that are non-textual (random binary junk) should not be shown. |
| 19 | + * The example test file has a comment with a 0x5 byte in it which is a control character |
| 20 | + * and considered binary junk for our purposes. |
| 21 | + */ |
| 22 | + public function testBinaryCommentStripped() { |
| 23 | + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' ); |
| 24 | + $this->assertEmpty( $res['COM'] ); |
| 25 | + } |
| 26 | + /* Very rarely a file can have multiple comments. |
| 27 | + * Order of comments is based on order inside the file. |
| 28 | + */ |
| 29 | + public function testMultipleComment() { |
| 30 | + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' ); |
| 31 | + $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] ); |
| 32 | + } |
| 33 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/media/JpegMetadataExtractorTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 34 | + native |
Index: trunk/phase3/tests/phpunit/data/media/jpeg-comment-binary.jpg |
Cannot display: file marked as a binary type. |
svn:mime-type = image/jpeg |
Property changes on: trunk/phase3/tests/phpunit/data/media/jpeg-comment-binary.jpg |
___________________________________________________________________ |
Added: svn:mime-type |
2 | 35 | + image/jpeg |
Index: trunk/phase3/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg |
Cannot display: file marked as a binary type. |
svn:mime-type = image/jpeg |
Property changes on: trunk/phase3/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg |
___________________________________________________________________ |
Added: svn:mime-type |
3 | 36 | + image/jpeg |
Index: trunk/phase3/tests/phpunit/data/media/README |
— | — | @@ -21,7 +21,8 @@ |
22 | 22 | |
23 | 23 | greyscale-na-png.png, rgb-png.png, Xmp-exif-multilingual_test.jpg |
24 | 24 | greyscale-png.png, 1bit-png.png, Png-native-test.png, rgb-na-png.png, |
25 | | -test.tiff, test.jpg |
| 25 | +test.tiff, test.jpg, jpeg-comment-multiple.jpg, jpeg-comment-utf.jpg, |
| 26 | +jpeg-comment-iso8859-1.jpg, jpeg-comment-binary.jpg |
26 | 27 | Are all by Bawolff. I don't think they contain enough originality to |
27 | 28 | claim copyright, but on the off chance they do, feel free to use them |
28 | 29 | however you feel fit, without restriction. |
Index: trunk/phase3/tests/phpunit/data/media/jpeg-comment-multiple.jpg |
Cannot display: file marked as a binary type. |
svn:mime-type = image/jpeg |
Property changes on: trunk/phase3/tests/phpunit/data/media/jpeg-comment-multiple.jpg |
___________________________________________________________________ |
Added: svn:mime-type |
29 | 30 | + image/jpeg |
Index: trunk/phase3/tests/phpunit/data/media/jpeg-comment-utf.jpg |
Cannot display: file marked as a binary type. |
svn:mime-type = image/jpeg |
Property changes on: trunk/phase3/tests/phpunit/data/media/jpeg-comment-utf.jpg |
___________________________________________________________________ |
Added: svn:mime-type |
30 | 31 | + image/jpeg |