3 class BitmapScalingTest
extends MediaWikiTestCase
{
5 protected function setUp() {
8 $this->setMwGlobals( array(
9 'wgMaxImageArea' => 1.25e7
, // 3500x3500
10 'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
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 public static 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',
105 function testTooBigImage() {
106 $file = new FakeDimensionFile( array( 4000, 4000 ) );
107 $handler = new BitmapHandler
;
108 $params = array( 'width' => '3700' ); // Still bigger than max size.
109 $this->assertEquals( 'TransformParameterError',
110 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
113 function testTooBigMustRenderImage() {
114 $file = new FakeDimensionFile( array( 4000, 4000 ) );
115 $file->mustRender
= true;
116 $handler = new BitmapHandler
;
117 $params = array( 'width' => '5000' ); // Still bigger than max size.
118 $this->assertEquals( 'TransformParameterError',
119 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
122 function testImageArea() {
123 $file = new FakeDimensionFile( array( 7, 9 ) );
124 $handler = new BitmapHandler
;
125 $this->assertEquals( 63, $handler->getImageArea( $file ) );
129 class FakeDimensionFile
extends File
{
130 public $mustRender = false;
132 public function __construct( $dimensions ) {
133 parent
::__construct( Title
::makeTitle( NS_FILE
, 'Test' ),
134 new NullRepo( null ) );
136 $this->dimensions
= $dimensions;
139 public function getWidth( $page = 1 ) {
140 return $this->dimensions
[0];
143 public function getHeight( $page = 1 ) {
144 return $this->dimensions
[1];
147 public function mustRender() {
148 return $this->mustRender
;
151 public function getPath() {