3 class BitmapScalingTest
extends MediaWikiTestCase
{
5 protected function setUp() {
8 $this->setMwGlobals( array(
9 'wgMaxImageArea' => 1.25e7
, // 3500x3500
10 'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
15 * @dataProvider provideNormaliseParams
16 * @covers BitmapHandler::normaliseParams
18 public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
19 $file = new FakeDimensionFile( $fileDimensions );
20 $handler = new BitmapHandler
;
21 $valid = $handler->normaliseParams( $file, $params );
22 $this->assertTrue( $valid );
23 $this->assertEquals( $expectedParams, $params, $msg );
26 public static function provideNormaliseParams() {
28 /* Regular resize operations */
32 'width' => 512, 'height' => 384,
33 'physicalWidth' => 512, 'physicalHeight' => 384,
36 array( 'width' => 512 ),
37 'Resizing with width set',
42 'width' => 512, 'height' => 384,
43 'physicalWidth' => 512, 'physicalHeight' => 384,
46 array( 'width' => 512, 'height' => 768 ),
47 'Resizing with height set too high',
52 'width' => 512, 'height' => 384,
53 'physicalWidth' => 512, 'physicalHeight' => 384,
56 array( 'width' => 1024, 'height' => 384 ),
57 'Resizing with height set',
60 /* Very tall images */
64 'width' => 5, 'height' => 1,
65 'physicalWidth' => 5, 'physicalHeight' => 1,
68 array( 'width' => 5 ),
75 'width' => 1, 'height' => 10,
76 'physicalWidth' => 1, 'physicalHeight' => 10,
79 array( 'width' => 1 ),
85 'width' => 1, 'height' => 5,
86 'physicalWidth' => 1, 'physicalHeight' => 10,
89 array( 'width' => 10, 'height' => 5 ),
90 'Very high image with height set',
96 'width' => 5000, 'height' => 5000,
97 'physicalWidth' => 4000, 'physicalHeight' => 4000,
100 array( 'width' => 5000 ),
101 'Bigger than max image size but doesn\'t need scaling',
107 * @covers BitmapHandler::doTransform
109 public function testTooBigImage() {
110 $file = new FakeDimensionFile( array( 4000, 4000 ) );
111 $handler = new BitmapHandler
;
112 $params = array( 'width' => '3700' ); // Still bigger than max size.
113 $this->assertEquals( 'TransformParameterError',
114 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
118 * @covers BitmapHandler::doTransform
120 public function testTooBigMustRenderImage() {
121 $file = new FakeDimensionFile( array( 4000, 4000 ) );
122 $file->mustRender
= true;
123 $handler = new BitmapHandler
;
124 $params = array( 'width' => '5000' ); // Still bigger than max size.
125 $this->assertEquals( 'TransformParameterError',
126 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
130 * @covers BitmapHandler::getImageArea
132 public function testImageArea() {
133 $file = new FakeDimensionFile( array( 7, 9 ) );
134 $handler = new BitmapHandler
;
135 $this->assertEquals( 63, $handler->getImageArea( $file ) );