Merge "Update Igbo namespaces"
[mediawiki.git] / tests / phpunit / includes / media / BitmapScalingTest.php
blob46e688eb3f9d2889e7b5b849c8379c4f82f77a64
1 <?php
3 use MediaWiki\MainConfigNames;
5 /**
6 * @group Media
7 */
8 class BitmapScalingTest extends MediaWikiIntegrationTestCase {
10 protected function setUp(): void {
11 parent::setUp();
13 $this->overrideConfigValues( [
14 MainConfigNames::MaxImageArea => 1.25e7, // 3500x3500
15 MainConfigNames::CustomConvertCommand => 'dummy', // Set so that we don't get client side rendering
16 ] );
19 /**
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() {
32 return [
33 /* Regular resize operations */
35 [ 1024, 768 ],
37 'width' => 512, 'height' => 384,
38 'physicalWidth' => 512, 'physicalHeight' => 384,
39 'page' => 1, 'interlace' => false,
41 [ 'width' => 512 ],
42 'Resizing with width set',
45 [ 1024, 768 ],
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',
55 [ 1024, 768 ],
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 */
67 [ 1000, 100 ],
69 'width' => 5, 'height' => 1,
70 'physicalWidth' => 5, 'physicalHeight' => 1,
71 'page' => 1, 'interlace' => false,
73 [ 'width' => 5 ],
74 'Very wide image',
78 [ 100, 1000 ],
80 'width' => 1, 'height' => 10,
81 'physicalWidth' => 1, 'physicalHeight' => 10,
82 'page' => 1, 'interlace' => false,
84 [ 'width' => 1 ],
85 'Very high image',
88 [ 100, 1000 ],
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',
97 /* Max image area */
99 [ 4000, 4000 ],
101 'width' => 5000, 'height' => 5000,
102 'physicalWidth' => 4000, 'physicalHeight' => 4000,
103 'page' => 1, 'interlace' => false,
105 [ 'width' => 5000 ],
106 'Bigger than max image size but doesn\'t need scaling',
108 /* Max interlace image area */
110 [ 4000, 4000 ],
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 ) );