Merge "Add ParserOutputStashForEdit hook for extension cache warming"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / BitmapScalingTest.php
index 3de60b7..d355e17 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+/**
+ * @group Media
+ */
 class BitmapScalingTest extends MediaWikiTestCase {
 
        protected function setUp() {
@@ -13,8 +16,9 @@ class BitmapScalingTest extends MediaWikiTestCase {
 
        /**
         * @dataProvider provideNormaliseParams
+        * @covers BitmapHandler::normaliseParams
         */
-       function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
+       public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
                $file = new FakeDimensionFile( $fileDimensions );
                $handler = new BitmapHandler;
                $valid = $handler->normaliseParams( $file, $params );
@@ -22,7 +26,7 @@ class BitmapScalingTest extends MediaWikiTestCase {
                $this->assertEquals( $expectedParams, $params, $msg );
        }
 
-       function provideNormaliseParams() {
+       public static function provideNormaliseParams() {
                return array(
                        /* Regular resize operations */
                        array(
@@ -30,7 +34,7 @@ class BitmapScalingTest extends MediaWikiTestCase {
                                array(
                                        'width' => 512, 'height' => 384,
                                        'physicalWidth' => 512, 'physicalHeight' => 384,
-                                       'page' => 1,
+                                       'page' => 1, 'interlace' => false,
                                ),
                                array( 'width' => 512 ),
                                'Resizing with width set',
@@ -40,7 +44,7 @@ class BitmapScalingTest extends MediaWikiTestCase {
                                array(
                                        'width' => 512, 'height' => 384,
                                        'physicalWidth' => 512, 'physicalHeight' => 384,
-                                       'page' => 1,
+                                       'page' => 1, 'interlace' => false,
                                ),
                                array( 'width' => 512, 'height' => 768 ),
                                'Resizing with height set too high',
@@ -50,7 +54,7 @@ class BitmapScalingTest extends MediaWikiTestCase {
                                array(
                                        'width' => 512, 'height' => 384,
                                        'physicalWidth' => 512, 'physicalHeight' => 384,
-                                       'page' => 1,
+                                       'page' => 1, 'interlace' => false,
                                ),
                                array( 'width' => 1024, 'height' => 384 ),
                                'Resizing with height set',
@@ -62,7 +66,7 @@ class BitmapScalingTest extends MediaWikiTestCase {
                                array(
                                        'width' => 5, 'height' => 1,
                                        'physicalWidth' => 5, 'physicalHeight' => 1,
-                                       'page' => 1,
+                                       'page' => 1, 'interlace' => false,
                                ),
                                array( 'width' => 5 ),
                                'Very wide image',
@@ -73,7 +77,7 @@ class BitmapScalingTest extends MediaWikiTestCase {
                                array(
                                        'width' => 1, 'height' => 10,
                                        'physicalWidth' => 1, 'physicalHeight' => 10,
-                                       'page' => 1,
+                                       'page' => 1, 'interlace' => false,
                                ),
                                array( 'width' => 1 ),
                                'Very high image',
@@ -83,7 +87,7 @@ class BitmapScalingTest extends MediaWikiTestCase {
                                array(
                                        'width' => 1, 'height' => 5,
                                        'physicalWidth' => 1, 'physicalHeight' => 10,
-                                       'page' => 1,
+                                       'page' => 1, 'interlace' => false,
                                ),
                                array( 'width' => 10, 'height' => 5 ),
                                'Very high image with height set',
@@ -94,61 +98,54 @@ class BitmapScalingTest extends MediaWikiTestCase {
                                array(
                                        'width' => 5000, 'height' => 5000,
                                        'physicalWidth' => 4000, 'physicalHeight' => 4000,
-                                       'page' => 1,
+                                       'page' => 1, 'interlace' => false,
                                ),
                                array( 'width' => 5000 ),
                                'Bigger than max image size but doesn\'t need scaling',
                        ),
+                       /* Max interlace image area */
+                       array(
+                               array( 4000, 4000 ),
+                               array(
+                                       'width' => 5000, 'height' => 5000,
+                                       'physicalWidth' => 4000, 'physicalHeight' => 4000,
+                                       'page' => 1, 'interlace' => false,
+                               ),
+                               array( 'width' => 5000, 'interlace' => true ),
+                               'Interlace bigger than max interlace area',
+                       ),
                );
        }
 
-       function testTooBigImage() {
+       /**
+        * @covers BitmapHandler::doTransform
+        */
+       public function testTooBigImage() {
                $file = new FakeDimensionFile( array( 4000, 4000 ) );
                $handler = new BitmapHandler;
                $params = array( 'width' => '3700' ); // Still bigger than max size.
-               $this->assertEquals( 'TransformParameterError',
+               $this->assertEquals( 'TransformTooBigImageAreaError',
                        get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
        }
 
-       function testTooBigMustRenderImage() {
+       /**
+        * @covers BitmapHandler::doTransform
+        */
+       public function testTooBigMustRenderImage() {
                $file = new FakeDimensionFile( array( 4000, 4000 ) );
                $file->mustRender = true;
                $handler = new BitmapHandler;
                $params = array( 'width' => '5000' ); // Still bigger than max size.
-               $this->assertEquals( 'TransformParameterError',
+               $this->assertEquals( 'TransformTooBigImageAreaError',
                        get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
        }
 
-       function testImageArea() {
+       /**
+        * @covers BitmapHandler::getImageArea
+        */
+       public function testImageArea() {
                $file = new FakeDimensionFile( array( 7, 9 ) );
                $handler = new BitmapHandler;
                $this->assertEquals( 63, $handler->getImageArea( $file ) );
        }
 }
-
-class FakeDimensionFile extends File {
-       public $mustRender = false;
-
-       public function __construct( $dimensions ) {
-               parent::__construct( Title::makeTitle( NS_FILE, 'Test' ),
-                       new NullRepo( null ) );
-
-               $this->dimensions = $dimensions;
-       }
-
-       public function getWidth( $page = 1 ) {
-               return $this->dimensions[0];
-       }
-
-       public function getHeight( $page = 1 ) {
-               return $this->dimensions[1];
-       }
-
-       public function mustRender() {
-               return $this->mustRender;
-       }
-
-       public function getPath() {
-               return '';
-       }
-}