follow-up r86169: unit tests for extraction of JPEG comment (COM) segments.
authorBrian Wolff <bawolff@users.mediawiki.org>
Thu, 18 Aug 2011 05:45:04 +0000 (05:45 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Thu, 18 Aug 2011 05:45:04 +0000 (05:45 +0000)
tests/phpunit/data/media/README
tests/phpunit/data/media/jpeg-comment-binary.jpg [new file with mode: 0644]
tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg [new file with mode: 0644]
tests/phpunit/data/media/jpeg-comment-multiple.jpg [new file with mode: 0644]
tests/phpunit/data/media/jpeg-comment-utf.jpg [new file with mode: 0644]
tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
tests/phpunit/includes/media/JpegMetadataExtractorTest.php [new file with mode: 0644]

index 224db9a..864e9ff 100644 (file)
@@ -21,7 +21,8 @@ TastyCakes on English Wikipedia
 
 greyscale-na-png.png, rgb-png.png, Xmp-exif-multilingual_test.jpg
 greyscale-png.png, 1bit-png.png, Png-native-test.png, rgb-na-png.png,
-test.tiff, test.jpg
+test.tiff, test.jpg, jpeg-comment-multiple.jpg, jpeg-comment-utf.jpg,
+jpeg-comment-iso8859-1.jpg, jpeg-comment-binary.jpg
 Are all by Bawolff. I don't think they contain enough originality to
 claim copyright, but on the off chance they do, feel free to use them
 however you feel fit, without restriction.
diff --git a/tests/phpunit/data/media/jpeg-comment-binary.jpg b/tests/phpunit/data/media/jpeg-comment-binary.jpg
new file mode 100644 (file)
index 0000000..b467fe4
Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-binary.jpg differ
diff --git a/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg b/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg
new file mode 100644 (file)
index 0000000..d9ffbac
Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-iso8859-1.jpg differ
diff --git a/tests/phpunit/data/media/jpeg-comment-multiple.jpg b/tests/phpunit/data/media/jpeg-comment-multiple.jpg
new file mode 100644 (file)
index 0000000..363c738
Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-multiple.jpg differ
diff --git a/tests/phpunit/data/media/jpeg-comment-utf.jpg b/tests/phpunit/data/media/jpeg-comment-utf.jpg
new file mode 100644 (file)
index 0000000..d6d35b4
Binary files /dev/null and b/tests/phpunit/data/media/jpeg-comment-utf.jpg differ
index a587bbe..148b90a 100644 (file)
@@ -32,4 +32,19 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
 
                $this->assertEquals( $expected, $meta['ImageDescription'] );
        }
+
+       /**
+        * Test for jpeg comments are being handled by
+        * BitmapMetadataHandler correctly.
+        *
+        * There's more extensive tests of comment extraction in
+        * JpegMetadataExtractorTests.php
+        */
+       public function testJpegComment() {
+               $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
+                       'jpeg-comment-utf.jpg' );
+
+               $this->assertEquals( 'UTF-8 JPEG Comment — ¼',
+                       $meta['JPEGFileComment'][0] );
+       }
 }
diff --git a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php
new file mode 100644 (file)
index 0000000..cc57925
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+class JpegMetadataExtractorTest extends MediaWikiTestCase {
+
+       public function setUp() {
+               $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
+       }
+
+       public function testUtf8Comment() {
+               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-utf.jpg' );
+               $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] );
+       }
+       /** The file is iso-8859-1, but it should get auto converted */
+       public function testIso88591Comment() {
+               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' );
+               $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] );
+       }
+       /** Comment values that are non-textual (random binary junk) should not be shown.
+        * The example test file has a comment with a 0x5 byte in it which is a control character
+        * and considered binary junk for our purposes.
+        */
+       public function testBinaryCommentStripped() {
+               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-binary.jpg' );
+               $this->assertEmpty( $res['COM'] );
+       }
+       /* Very rarely a file can have multiple comments.
+        *   Order of comments is based on order inside the file.
+        */
+       public function testMultipleComment() {
+               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' );
+               $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] );
+       }
+}