3 use MediaWiki\MainConfigNames
;
8 class BitmapScalingTest
extends MediaWikiIntegrationTestCase
{
10 protected function setUp(): void
{
13 $this->overrideConfigValues( [
14 MainConfigNames
::MaxImageArea
=> 1.25e7
, // 3500x3500
15 MainConfigNames
::CustomConvertCommand
=> 'dummy', // Set so that we don't get client side rendering
20 * @dataProvider provideNormaliseParams
21 * @covers \BitmapHandler::normaliseParams
23 public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
24 $file = new FakeDimensionFile( $fileDimensions );
25 $handler = new BitmapHandler
;
26 $valid = $handler->normaliseParams( $file, $params );
27 $this->assertTrue( $valid );
28 $this->assertEquals( $expectedParams, $params, $msg );
31 public static function provideNormaliseParams() {
33 /* Regular resize operations */
37 'width' => 512, 'height' => 384,
38 'physicalWidth' => 512, 'physicalHeight' => 384,
39 'page' => 1, 'interlace' => false,
42 'Resizing with width set',
47 'width' => 512, 'height' => 384,
48 'physicalWidth' => 512, 'physicalHeight' => 384,
49 'page' => 1, 'interlace' => false,
51 [ 'width' => 512, 'height' => 768 ],
52 'Resizing with height set too high',
57 'width' => 512, 'height' => 384,
58 'physicalWidth' => 512, 'physicalHeight' => 384,
59 'page' => 1, 'interlace' => false,
61 [ 'width' => 1024, 'height' => 384 ],
62 'Resizing with height set',
65 /* Very tall images */
69 'width' => 5, 'height' => 1,
70 'physicalWidth' => 5, 'physicalHeight' => 1,
71 'page' => 1, 'interlace' => false,
80 'width' => 1, 'height' => 10,
81 'physicalWidth' => 1, 'physicalHeight' => 10,
82 'page' => 1, 'interlace' => false,
90 'width' => 1, 'height' => 5,
91 'physicalWidth' => 1, 'physicalHeight' => 10,
92 'page' => 1, 'interlace' => false,
94 [ 'width' => 10, 'height' => 5 ],
95 'Very high image with height set',
101 'width' => 5000, 'height' => 5000,
102 'physicalWidth' => 4000, 'physicalHeight' => 4000,
103 'page' => 1, 'interlace' => false,
106 'Bigger than max image size but doesn\'t need scaling',
108 /* Max interlace image area */
112 'width' => 5000, 'height' => 5000,
113 'physicalWidth' => 4000, 'physicalHeight' => 4000,
114 'page' => 1, 'interlace' => false,
116 [ 'width' => 5000, 'interlace' => true ],
117 'Interlace bigger than max interlace area',
123 * @covers \BitmapHandler::doTransform
125 public function testTooBigImage() {
126 $file = new FakeDimensionFile( [ 4000, 4000 ] );
127 $handler = new BitmapHandler
;
128 $params = [ 'width' => '3700' ]; // Still bigger than max size.
129 $this->assertEquals( TransformTooBigImageAreaError
::class,
130 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
134 * @covers \BitmapHandler::doTransform
136 public function testTooBigMustRenderImage() {
137 $file = new FakeDimensionFile( [ 4000, 4000 ] );
138 $file->mustRender
= true;
139 $handler = new BitmapHandler
;
140 $params = [ 'width' => '5000' ]; // Still bigger than max size.
141 $this->assertEquals( TransformTooBigImageAreaError
::class,
142 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
146 * @covers \BitmapHandler::getImageArea
148 public function testImageArea() {
149 $file = new FakeDimensionFile( [ 7, 9 ] );
150 $handler = new BitmapHandler
;
151 $this->assertEquals( 63, $handler->getImageArea( $file ) );