2011-07-15 19:03:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
2014-07-15 17:31:07 +00:00
|
|
|
/**
|
|
|
|
|
* @group Media
|
|
|
|
|
*/
|
2011-07-15 19:03:40 +00:00
|
|
|
class BitmapScalingTest extends MediaWikiTestCase {
|
2011-09-09 20:13:09 +00:00
|
|
|
|
2019-10-20 18:11:08 +00:00
|
|
|
protected function setUp() : void {
|
2012-10-08 10:56:20 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2012-10-08 10:56:20 +00:00
|
|
|
'wgMaxImageArea' => 1.25e7, // 3500x3500
|
|
|
|
|
'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2011-09-09 20:13:09 +00:00
|
|
|
}
|
2012-10-08 10:56:20 +00:00
|
|
|
|
2011-07-15 19:03:40 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideNormaliseParams
|
2013-10-23 22:12:39 +00:00
|
|
|
* @covers BitmapHandler::normaliseParams
|
2011-07-15 19:03:40 +00:00
|
|
|
*/
|
2013-10-23 22:12:39 +00:00
|
|
|
public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
|
2011-07-15 19:03:40 +00:00
|
|
|
$file = new FakeDimensionFile( $fileDimensions );
|
|
|
|
|
$handler = new BitmapHandler;
|
2011-09-09 20:13:09 +00:00
|
|
|
$valid = $handler->normaliseParams( $file, $params );
|
|
|
|
|
$this->assertTrue( $valid );
|
2011-07-15 19:03:40 +00:00
|
|
|
$this->assertEquals( $expectedParams, $params, $msg );
|
|
|
|
|
}
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provideNormaliseParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2013-02-15 10:17:52 +00:00
|
|
|
/* Regular resize operations */
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[ 1024, 768 ],
|
|
|
|
|
[
|
2013-02-15 10:17:52 +00:00
|
|
|
'width' => 512, 'height' => 384,
|
2011-07-15 19:03:40 +00:00
|
|
|
'physicalWidth' => 512, 'physicalHeight' => 384,
|
2016-01-14 02:13:11 +00:00
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 512 ],
|
2011-07-15 19:03:40 +00:00
|
|
|
'Resizing with width set',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[ 1024, 768 ],
|
|
|
|
|
[
|
2013-02-15 10:17:52 +00:00
|
|
|
'width' => 512, 'height' => 384,
|
2011-07-15 19:03:40 +00:00
|
|
|
'physicalWidth' => 512, 'physicalHeight' => 384,
|
2016-01-14 02:13:11 +00:00
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 512, 'height' => 768 ],
|
2011-07-15 19:03:40 +00:00
|
|
|
'Resizing with height set too high',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[ 1024, 768 ],
|
|
|
|
|
[
|
2013-02-15 10:17:52 +00:00
|
|
|
'width' => 512, 'height' => 384,
|
2011-07-15 19:03:40 +00:00
|
|
|
'physicalWidth' => 512, 'physicalHeight' => 384,
|
2016-01-14 02:13:11 +00:00
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 1024, 'height' => 384 ],
|
2011-07-15 19:03:40 +00:00
|
|
|
'Resizing with height set',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2011-07-15 19:03:40 +00:00
|
|
|
/* Very tall images */
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[ 1000, 100 ],
|
|
|
|
|
[
|
2011-07-15 19:03:40 +00:00
|
|
|
'width' => 5, 'height' => 1,
|
|
|
|
|
'physicalWidth' => 5, 'physicalHeight' => 1,
|
2016-01-14 02:13:11 +00:00
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 5 ],
|
2011-07-15 19:03:40 +00:00
|
|
|
'Very wide image',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[ 100, 1000 ],
|
|
|
|
|
[
|
2011-07-15 19:03:40 +00:00
|
|
|
'width' => 1, 'height' => 10,
|
|
|
|
|
'physicalWidth' => 1, 'physicalHeight' => 10,
|
2016-01-14 02:13:11 +00:00
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 1 ],
|
2011-07-15 19:03:40 +00:00
|
|
|
'Very high image',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[ 100, 1000 ],
|
|
|
|
|
[
|
2011-07-15 19:03:40 +00:00
|
|
|
'width' => 1, 'height' => 5,
|
|
|
|
|
'physicalWidth' => 1, 'physicalHeight' => 10,
|
2016-01-14 02:13:11 +00:00
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 10, 'height' => 5 ],
|
2011-07-15 19:03:40 +00:00
|
|
|
'Very high image with height set',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2011-09-09 20:13:09 +00:00
|
|
|
/* Max image area */
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[ 4000, 4000 ],
|
|
|
|
|
[
|
2011-09-09 20:13:09 +00:00
|
|
|
'width' => 5000, 'height' => 5000,
|
|
|
|
|
'physicalWidth' => 4000, 'physicalHeight' => 4000,
|
2016-01-14 02:13:11 +00:00
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 5000 ],
|
2011-09-09 20:13:09 +00:00
|
|
|
'Bigger than max image size but doesn\'t need scaling',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-01-14 02:13:11 +00:00
|
|
|
/* Max interlace image area */
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
[ 4000, 4000 ],
|
|
|
|
|
[
|
2016-01-14 02:13:11 +00:00
|
|
|
'width' => 5000, 'height' => 5000,
|
|
|
|
|
'physicalWidth' => 4000, 'physicalHeight' => 4000,
|
|
|
|
|
'page' => 1, 'interlace' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ 'width' => 5000, 'interlace' => true ],
|
2016-01-14 02:13:11 +00:00
|
|
|
'Interlace bigger than max interlace area',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2012-10-08 10:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-23 22:12:39 +00:00
|
|
|
/**
|
|
|
|
|
* @covers BitmapHandler::doTransform
|
|
|
|
|
*/
|
|
|
|
|
public function testTooBigImage() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$file = new FakeDimensionFile( [ 4000, 4000 ] );
|
2011-09-09 20:13:09 +00:00
|
|
|
$handler = new BitmapHandler;
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [ 'width' => '3700' ]; // Still bigger than max size.
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertEquals( TransformTooBigImageAreaError::class,
|
2011-10-15 21:38:53 +00:00
|
|
|
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
|
2011-09-09 20:13:09 +00:00
|
|
|
}
|
2012-10-08 10:56:20 +00:00
|
|
|
|
2013-10-23 22:12:39 +00:00
|
|
|
/**
|
|
|
|
|
* @covers BitmapHandler::doTransform
|
|
|
|
|
*/
|
|
|
|
|
public function testTooBigMustRenderImage() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$file = new FakeDimensionFile( [ 4000, 4000 ] );
|
2011-09-09 20:13:09 +00:00
|
|
|
$file->mustRender = true;
|
|
|
|
|
$handler = new BitmapHandler;
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [ 'width' => '5000' ]; // Still bigger than max size.
|
2018-01-13 00:02:09 +00:00
|
|
|
$this->assertEquals( TransformTooBigImageAreaError::class,
|
2011-10-15 21:38:53 +00:00
|
|
|
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
|
2011-09-09 20:13:09 +00:00
|
|
|
}
|
2013-02-15 10:17:52 +00:00
|
|
|
|
2013-10-23 22:12:39 +00:00
|
|
|
/**
|
|
|
|
|
* @covers BitmapHandler::getImageArea
|
|
|
|
|
*/
|
|
|
|
|
public function testImageArea() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$file = new FakeDimensionFile( [ 7, 9 ] );
|
2011-11-02 20:48:50 +00:00
|
|
|
$handler = new BitmapHandler;
|
|
|
|
|
$this->assertEquals( 63, $handler->getImageArea( $file ) );
|
|
|
|
|
}
|
2011-07-15 19:03:40 +00:00
|
|
|
}
|