3 class BitmapScalingTest
extends MediaWikiTestCase
{
6 global $wgMaxImageArea;
7 $this->oldMaxImageArea
= $wgMaxImageArea;
8 $wgMaxImageArea = 1.25e7
; // 3500x3500
11 global $wgMaxImageArea;
12 $wgMaxImageArea = $this->oldMaxImageArea
;
15 * @dataProvider provideNormaliseParams
17 function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
18 $file = new FakeDimensionFile( $fileDimensions );
19 $handler = new BitmapHandler
;
20 $valid = $handler->normaliseParams( $file, $params );
21 $this->assertTrue( $valid );
22 $this->assertEquals( $expectedParams, $params, $msg );
25 function provideNormaliseParams() {
27 /* Regular resize operations */
31 'width' => 512, 'height' => 384,
32 'physicalWidth' => 512, 'physicalHeight' => 384,
35 array( 'width' => 512 ),
36 'Resizing with width set',
41 'width' => 512, 'height' => 384,
42 'physicalWidth' => 512, 'physicalHeight' => 384,
45 array( 'width' => 512, 'height' => 768 ),
46 'Resizing with height set too high',
51 'width' => 512, 'height' => 384,
52 'physicalWidth' => 512, 'physicalHeight' => 384,
55 array( 'width' => 1024, 'height' => 384 ),
56 'Resizing with height set',
59 /* Very tall images */
63 'width' => 5, 'height' => 1,
64 'physicalWidth' => 5, 'physicalHeight' => 1,
67 array( 'width' => 5 ),
74 'width' => 1, 'height' => 10,
75 'physicalWidth' => 1, 'physicalHeight' => 10,
78 array( 'width' => 1 ),
84 'width' => 1, 'height' => 5,
85 'physicalWidth' => 1, 'physicalHeight' => 10,
88 array( 'width' => 10, 'height' => 5 ),
89 'Very high image with height set',
95 'width' => 5000, 'height' => 5000,
96 'physicalWidth' => 4000, 'physicalHeight' => 4000,
99 array( 'width' => 5000 ),
100 'Bigger than max image size but doesn\'t need scaling',
104 function testTooBigImage() {
105 $file = new FakeDimensionFile( array( 4000, 4000 ) );
106 $handler = new BitmapHandler
;
107 $params = array( 'width' => '3700' ); // Still bigger than max size.
108 $this->assertFalse( $handler->normaliseParams( $file, $params ) );
110 function testTooBigMustRenderImage() {
111 $file = new FakeDimensionFile( array( 4000, 4000 ) );
112 $file->mustRender
= true;
113 $handler = new BitmapHandler
;
114 $params = array( 'width' => '5000' ); // Still bigger than max size.
115 $this->assertFalse( $handler->normaliseParams( $file, $params ) );
119 class FakeDimensionFile
extends File
{
120 public $mustRender = false;
122 public function __construct( $dimensions ) {
123 parent
::__construct( Title
::makeTitle( NS_FILE
, 'Test' ), null );
125 $this->dimensions
= $dimensions;
127 public function getWidth( $page = 1 ) {
128 return $this->dimensions
[0];
130 public function getHeight( $page = 1 ) {
131 return $this->dimensions
[1];
133 public function mustRender() {
134 return $this->mustRender
;