Type hint against LinkTarget in WatchedItemStore
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegMetadataExtractorTest.php
index 7ffde3b..c943cef 100644 (file)
@@ -6,6 +6,7 @@
  * but it costs money). The implementation of it currently in MediaWiki is based
  * solely on reading the standard, without any real world test files.
  *
+ * @group Media
  * @covers JpegMetadataExtractor
  */
 class JpegMetadataExtractorTest extends MediaWikiTestCase {
@@ -22,27 +23,27 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase {
         * We also use this test to test padding bytes don't
         * screw stuff up
         *
-        * @param string $file filename
+        * @param string $file Filename
         *
         * @dataProvider provideUtf8Comment
         */
        public function testUtf8Comment( $file ) {
                $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file );
-               $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] );
+               $this->assertEquals( [ 'UTF-8 JPEG Comment — ¼' ], $res['COM'] );
        }
 
        public static function provideUtf8Comment() {
-               return array(
-                       array( 'jpeg-comment-utf.jpg' ),
-                       array( 'jpeg-padding-even.jpg' ),
-                       array( 'jpeg-padding-odd.jpg' ),
-               );
+               return [
+                       [ 'jpeg-comment-utf.jpg' ],
+                       [ 'jpeg-padding-even.jpg' ],
+                       [ 'jpeg-padding-odd.jpg' ],
+               ];
        }
 
        /** 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'] );
+               $this->assertEquals( [ 'ISO-8859-1 JPEG Comment - ¼' ], $res['COM'] );
        }
 
        /** Comment values that are non-textual (random binary junk) should not be shown.
@@ -59,7 +60,7 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase {
         */
        public function testMultipleComment() {
                $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' );
-               $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] );
+               $this->assertEquals( [ 'foo', 'bar' ], $res['COM'] );
        }
 
        public function testXMPExtraction() {
@@ -70,7 +71,8 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase {
 
        public function testPSIRExtraction() {
                $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-psir.jpg' );
-               $expected = '50686f746f73686f7020332e30003842494d04040000000000181c02190004746573741c02190003666f6f1c020000020004';
+               $expected = '50686f746f73686f7020332e30003842494d04040000000'
+                       . '000181c02190004746573741c02190003666f6f1c020000020004';
                $this->assertEquals( $expected, bin2hex( $res['PSIR'][0] ) );
        }
 
@@ -106,4 +108,21 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase {
                $expected = 'BE';
                $this->assertEquals( $expected, $res['byteOrder'] );
        }
+
+       public function testInfiniteRead() {
+               // test file truncated right after a segment, which previously
+               // caused an infinite loop looking for the next segment byte.
+               // Should get past infinite loop and throw in wfUnpack()
+               $this->setExpectedException( 'MWException' );
+               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-segment-loop1.jpg' );
+       }
+
+       public function testInfiniteRead2() {
+               // test file truncated after a segment's marker and size, which
+               // would cause a seek past end of file. Seek past end of file
+               // doesn't actually fail, but prevents further reading and was
+               // devolving into the previous case (testInfiniteRead).
+               $this->setExpectedException( 'MWException' );
+               $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-segment-loop2.jpg' );
+       }
 }