MediaWiki  1.28.0
BitmapScalingTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  protected function setUp() {
9  parent::setUp();
10 
11  $this->setMwGlobals( [
12  'wgMaxImageArea' => 1.25e7, // 3500x3500
13  'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
14  ] );
15  }
16 
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 );
27  }
28 
29  public static function provideNormaliseParams() {
30  return [
31  /* Regular resize operations */
32  [
33  [ 1024, 768 ],
34  [
35  'width' => 512, 'height' => 384,
36  'physicalWidth' => 512, 'physicalHeight' => 384,
37  'page' => 1, 'interlace' => false,
38  ],
39  [ 'width' => 512 ],
40  'Resizing with width set',
41  ],
42  [
43  [ 1024, 768 ],
44  [
45  'width' => 512, 'height' => 384,
46  'physicalWidth' => 512, 'physicalHeight' => 384,
47  'page' => 1, 'interlace' => false,
48  ],
49  [ 'width' => 512, 'height' => 768 ],
50  'Resizing with height set too high',
51  ],
52  [
53  [ 1024, 768 ],
54  [
55  'width' => 512, 'height' => 384,
56  'physicalWidth' => 512, 'physicalHeight' => 384,
57  'page' => 1, 'interlace' => false,
58  ],
59  [ 'width' => 1024, 'height' => 384 ],
60  'Resizing with height set',
61  ],
62 
63  /* Very tall images */
64  [
65  [ 1000, 100 ],
66  [
67  'width' => 5, 'height' => 1,
68  'physicalWidth' => 5, 'physicalHeight' => 1,
69  'page' => 1, 'interlace' => false,
70  ],
71  [ 'width' => 5 ],
72  'Very wide image',
73  ],
74 
75  [
76  [ 100, 1000 ],
77  [
78  'width' => 1, 'height' => 10,
79  'physicalWidth' => 1, 'physicalHeight' => 10,
80  'page' => 1, 'interlace' => false,
81  ],
82  [ 'width' => 1 ],
83  'Very high image',
84  ],
85  [
86  [ 100, 1000 ],
87  [
88  'width' => 1, 'height' => 5,
89  'physicalWidth' => 1, 'physicalHeight' => 10,
90  'page' => 1, 'interlace' => false,
91  ],
92  [ 'width' => 10, 'height' => 5 ],
93  'Very high image with height set',
94  ],
95  /* Max image area */
96  [
97  [ 4000, 4000 ],
98  [
99  'width' => 5000, 'height' => 5000,
100  'physicalWidth' => 4000, 'physicalHeight' => 4000,
101  'page' => 1, 'interlace' => false,
102  ],
103  [ 'width' => 5000 ],
104  'Bigger than max image size but doesn\'t need scaling',
105  ],
106  /* Max interlace image area */
107  [
108  [ 4000, 4000 ],
109  [
110  'width' => 5000, 'height' => 5000,
111  'physicalWidth' => 4000, 'physicalHeight' => 4000,
112  'page' => 1, 'interlace' => false,
113  ],
114  [ 'width' => 5000, 'interlace' => true ],
115  'Interlace bigger than max interlace area',
116  ],
117  ];
118  }
119 
123  public function testTooBigImage() {
124  $file = new FakeDimensionFile( [ 4000, 4000 ] );
125  $handler = new BitmapHandler;
126  $params = [ 'width' => '3700' ]; // Still bigger than max size.
127  $this->assertEquals( 'TransformTooBigImageAreaError',
128  get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
129  }
130 
134  public function testTooBigMustRenderImage() {
135  $file = new FakeDimensionFile( [ 4000, 4000 ] );
136  $file->mustRender = true;
137  $handler = new BitmapHandler;
138  $params = [ 'width' => '5000' ]; // Still bigger than max size.
139  $this->assertEquals( 'TransformTooBigImageAreaError',
140  get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
141  }
142 
146  public function testImageArea() {
147  $file = new FakeDimensionFile( [ 7, 9 ] );
148  $handler = new BitmapHandler;
149  $this->assertEquals( 63, $handler->getImageArea( $file ) );
150  }
151 }
testTooBigImage()
BitmapHandler::doTransform.
testTooBigMustRenderImage()
BitmapHandler::doTransform.
testImageArea()
BitmapHandler::getImageArea.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1936
$params
static provideNormaliseParams()
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
testNormaliseParams($fileDimensions, $expectedParams, $params, $msg)
provideNormaliseParams BitmapHandler::normaliseParams
Generic handler for bitmap images.
Definition: Bitmap.php:29
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:802
setMwGlobals($pairs, $value=null)