6 class BitmapScalingTest
extends MediaWikiTestCase
{
8 protected function setUp() {
11 $this->setMwGlobals( array(
12 'wgMaxImageArea' => 1.25e7
, // 3500x3500
13 'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
18 * @dataProvider provideNormaliseParams
19 * @covers BitmapHandler::normaliseParams
21 public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
22 $file = new FakeDimensionFile( $fileDimensions );
23 $handler = new BitmapHandler
;
24 $valid = $handler->normaliseParams( $file, $params );
25 $this->assertTrue( $valid );
26 $this->assertEquals( $expectedParams, $params, $msg );
29 public static function provideNormaliseParams() {
31 /* Regular resize operations */
35 'width' => 512, 'height' => 384,
36 'physicalWidth' => 512, 'physicalHeight' => 384,
39 array( 'width' => 512 ),
40 'Resizing with width set',
45 'width' => 512, 'height' => 384,
46 'physicalWidth' => 512, 'physicalHeight' => 384,
49 array( 'width' => 512, 'height' => 768 ),
50 'Resizing with height set too high',
55 'width' => 512, 'height' => 384,
56 'physicalWidth' => 512, 'physicalHeight' => 384,
59 array( 'width' => 1024, 'height' => 384 ),
60 'Resizing with height set',
63 /* Very tall images */
67 'width' => 5, 'height' => 1,
68 'physicalWidth' => 5, 'physicalHeight' => 1,
71 array( 'width' => 5 ),
78 'width' => 1, 'height' => 10,
79 'physicalWidth' => 1, 'physicalHeight' => 10,
82 array( 'width' => 1 ),
88 'width' => 1, 'height' => 5,
89 'physicalWidth' => 1, 'physicalHeight' => 10,
92 array( 'width' => 10, 'height' => 5 ),
93 'Very high image with height set',
99 'width' => 5000, 'height' => 5000,
100 'physicalWidth' => 4000, 'physicalHeight' => 4000,
103 array( 'width' => 5000 ),
104 'Bigger than max image size but doesn\'t need scaling',
110 * @covers BitmapHandler::doTransform
112 public function testTooBigImage() {
113 $file = new FakeDimensionFile( array( 4000, 4000 ) );
114 $handler = new BitmapHandler
;
115 $params = array( 'width' => '3700' ); // Still bigger than max size.
116 $this->assertEquals( 'TransformTooBigImageAreaError',
117 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
121 * @covers BitmapHandler::doTransform
123 public function testTooBigMustRenderImage() {
124 $file = new FakeDimensionFile( array( 4000, 4000 ) );
125 $file->mustRender
= true;
126 $handler = new BitmapHandler
;
127 $params = array( 'width' => '5000' ); // Still bigger than max size.
128 $this->assertEquals( 'TransformTooBigImageAreaError',
129 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
133 * @covers BitmapHandler::getImageArea
135 public function testImageArea() {
136 $file = new FakeDimensionFile( array( 7, 9 ) );
137 $handler = new BitmapHandler
;
138 $this->assertEquals( 63, $handler->getImageArea( $file ) );