Debian Codegraph @

tests/phpunit/includes/media/BitmapScalingTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\MainConfigNames;
4
5 /**
6 * @group Media
7 */
8 class BitmapScalingTest extends MediaWikiIntegrationTestCase {
9
10 protected function setUp(): void {
11 parent::setUp();
12
13 $this->overrideConfigValues( [
14 MainConfigNames::MaxImageArea => 1.25e7, // 3500x3500
15 MainConfigNames::CustomConvertCommand => 'dummy', // Set so that we don't get client side rendering
16 ] );
17 }
18
19 /**
20 * @dataProvider provideNormaliseParams
21 * @covers \BitmapHandler::normaliseParams
22 */
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 );
29 }
30
31 public static function provideNormaliseParams() {
32 return [
33 /* Regular resize operations */
34 [
35 [ 1024, 768 ],
36 [
37 'width' => 512, 'height' => 384,
38 'physicalWidth' => 512, 'physicalHeight' => 384,
39 'page' => 1, 'interlace' => false,
40 ],
41 [ 'width' => 512 ],
42 'Resizing with width set',
43 ],
44 [
45 [ 1024, 768 ],
46 [
47 'width' => 512, 'height' => 384,
48 'physicalWidth' => 512, 'physicalHeight' => 384,
49 'page' => 1, 'interlace' => false,
50 ],
51 [ 'width' => 512, 'height' => 768 ],
52 'Resizing with height set too high',
53 ],
54 [
55 [ 1024, 768 ],
56 [
57 'width' => 512, 'height' => 384,
58 'physicalWidth' => 512, 'physicalHeight' => 384,
59 'page' => 1, 'interlace' => false,
60 ],
61 [ 'width' => 1024, 'height' => 384 ],
62 'Resizing with height set',
63 ],
64
65 /* Very tall images */
66 [
67 [ 1000, 100 ],
68 [
69 'width' => 5, 'height' => 1,
70 'physicalWidth' => 5, 'physicalHeight' => 1,
71 'page' => 1, 'interlace' => false,
72 ],
73 [ 'width' => 5 ],
74 'Very wide image',
75 ],
76
77 [
78 [ 100, 1000 ],
79 [
80 'width' => 1, 'height' => 10,
81 'physicalWidth' => 1, 'physicalHeight' => 10,
82 'page' => 1, 'interlace' => false,
83 ],
84 [ 'width' => 1 ],
85 'Very high image',
86 ],
87 [
88 [ 100, 1000 ],
89 [
90 'width' => 1, 'height' => 5,
91 'physicalWidth' => 1, 'physicalHeight' => 10,
92 'page' => 1, 'interlace' => false,
93 ],
94 [ 'width' => 10, 'height' => 5 ],
95 'Very high image with height set',
96 ],
97 /* Max image area */
98 [
99 [ 4000, 4000 ],
100 [
101 'width' => 5000, 'height' => 5000,
102 'physicalWidth' => 4000, 'physicalHeight' => 4000,
103 'page' => 1, 'interlace' => false,
104 ],
105 [ 'width' => 5000 ],
106 'Bigger than max image size but doesn\'t need scaling',
107 ],
108 /* Max interlace image area */
109 [
110 [ 4000, 4000 ],
111 [
112 'width' => 5000, 'height' => 5000,
113 'physicalWidth' => 4000, 'physicalHeight' => 4000,
114 'page' => 1, 'interlace' => false,
115 ],
116 [ 'width' => 5000, 'interlace' => true ],
117 'Interlace bigger than max interlace area',
118 ],
119 ];
120 }
121
122 /**
123 * @covers \BitmapHandler::doTransform
124 */
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 ) ) );
131 }
132
133 /**
134 * @covers \BitmapHandler::doTransform
135 */
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 ) ) );
143 }
144
145 /**
146 * @covers \BitmapHandler::getImageArea
147 */
148 public function testImageArea() {
149 $file = new FakeDimensionFile( [ 7, 9 ] );
150 $handler = new BitmapHandler;
151 $this->assertEquals( 63, $handler->getImageArea( $file ) );
152 }
153 }