3
class BitmapScalingTest extends MediaWikiTestCase {
6
global $wgMaxImageArea, $wgCustomConvertCommand;
7
$this->oldMaxImageArea = $wgMaxImageArea;
8
$this->oldCustomConvertCommand = $wgCustomConvertCommand;
9
$wgMaxImageArea = 1.25e7; // 3500x3500
10
$wgCustomConvertCommand = 'dummy'; // Set so that we don't get client side rendering
13
global $wgMaxImageArea, $wgCustomConvertCommand;
14
$wgMaxImageArea = $this->oldMaxImageArea;
15
$wgCustomConvertCommand = $this->oldCustomConvertCommand;
18
* @dataProvider provideNormaliseParams
20
function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
21
$file = new FakeDimensionFile( $fileDimensions );
22
$handler = new BitmapHandler;
23
$valid = $handler->normaliseParams( $file, $params );
24
$this->assertTrue( $valid );
25
$this->assertEquals( $expectedParams, $params, $msg );
28
function provideNormaliseParams() {
30
/* Regular resize operations */
34
'width' => 512, 'height' => 384,
35
'physicalWidth' => 512, 'physicalHeight' => 384,
38
array( 'width' => 512 ),
39
'Resizing with width set',
44
'width' => 512, 'height' => 384,
45
'physicalWidth' => 512, 'physicalHeight' => 384,
48
array( 'width' => 512, 'height' => 768 ),
49
'Resizing with height set too high',
54
'width' => 512, 'height' => 384,
55
'physicalWidth' => 512, 'physicalHeight' => 384,
58
array( 'width' => 1024, 'height' => 384 ),
59
'Resizing with height set',
62
/* Very tall images */
66
'width' => 5, 'height' => 1,
67
'physicalWidth' => 5, 'physicalHeight' => 1,
70
array( 'width' => 5 ),
77
'width' => 1, 'height' => 10,
78
'physicalWidth' => 1, 'physicalHeight' => 10,
81
array( 'width' => 1 ),
87
'width' => 1, 'height' => 5,
88
'physicalWidth' => 1, 'physicalHeight' => 10,
91
array( 'width' => 10, 'height' => 5 ),
92
'Very high image with height set',
98
'width' => 5000, 'height' => 5000,
99
'physicalWidth' => 4000, 'physicalHeight' => 4000,
102
array( 'width' => 5000 ),
103
'Bigger than max image size but doesn\'t need scaling',
107
function testTooBigImage() {
108
$file = new FakeDimensionFile( array( 4000, 4000 ) );
109
$handler = new BitmapHandler;
110
$params = array( 'width' => '3700' ); // Still bigger than max size.
111
$this->assertEquals( 'TransformParameterError',
112
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
114
function testTooBigMustRenderImage() {
115
$file = new FakeDimensionFile( array( 4000, 4000 ) );
116
$file->mustRender = true;
117
$handler = new BitmapHandler;
118
$params = array( 'width' => '5000' ); // Still bigger than max size.
119
$this->assertEquals( 'TransformParameterError',
120
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
123
function testImageArea() {
124
$file = new FakeDimensionFile( array( 7, 9 ) );
125
$handler = new BitmapHandler;
126
$this->assertEquals( 63, $handler->getImageArea( $file ) );
130
class FakeDimensionFile extends File {
131
public $mustRender = false;
133
public function __construct( $dimensions ) {
134
parent::__construct( Title::makeTitle( NS_FILE, 'Test' ),
135
new NullRepo( null ) );
137
$this->dimensions = $dimensions;
139
public function getWidth( $page = 1 ) {
140
return $this->dimensions[0];
142
public function getHeight( $page = 1 ) {
143
return $this->dimensions[1];
145
public function mustRender() {
146
return $this->mustRender;
148
public function getPath() {