wiki.techinc.nl/tests/phpunit/includes/media/BitmapScalingTest.php

152 lines
3.8 KiB
PHP
Raw Normal View History

<?php
/**
* @group Media
*/
class BitmapScalingTest extends MediaWikiTestCase {
protected function setUp() : void {
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
parent::setUp();
$this->setMwGlobals( [
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
'wgMaxImageArea' => 1.25e7, // 3500x3500
'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
] );
}
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
/**
* @dataProvider provideNormaliseParams
* @covers BitmapHandler::normaliseParams
*/
public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
$file = new FakeDimensionFile( $fileDimensions );
$handler = new BitmapHandler;
$valid = $handler->normaliseParams( $file, $params );
$this->assertTrue( $valid );
$this->assertEquals( $expectedParams, $params, $msg );
}
public static function provideNormaliseParams() {
return [
/* Regular resize operations */
[
[ 1024, 768 ],
[
'width' => 512, 'height' => 384,
'physicalWidth' => 512, 'physicalHeight' => 384,
'page' => 1, 'interlace' => false,
],
[ 'width' => 512 ],
'Resizing with width set',
],
[
[ 1024, 768 ],
[
'width' => 512, 'height' => 384,
'physicalWidth' => 512, 'physicalHeight' => 384,
'page' => 1, 'interlace' => false,
],
[ 'width' => 512, 'height' => 768 ],
'Resizing with height set too high',
],
[
[ 1024, 768 ],
[
'width' => 512, 'height' => 384,
'physicalWidth' => 512, 'physicalHeight' => 384,
'page' => 1, 'interlace' => false,
],
[ 'width' => 1024, 'height' => 384 ],
'Resizing with height set',
],
/* Very tall images */
[
[ 1000, 100 ],
[
'width' => 5, 'height' => 1,
'physicalWidth' => 5, 'physicalHeight' => 1,
'page' => 1, 'interlace' => false,
],
[ 'width' => 5 ],
'Very wide image',
],
[
[ 100, 1000 ],
[
'width' => 1, 'height' => 10,
'physicalWidth' => 1, 'physicalHeight' => 10,
'page' => 1, 'interlace' => false,
],
[ 'width' => 1 ],
'Very high image',
],
[
[ 100, 1000 ],
[
'width' => 1, 'height' => 5,
'physicalWidth' => 1, 'physicalHeight' => 10,
'page' => 1, 'interlace' => false,
],
[ 'width' => 10, 'height' => 5 ],
'Very high image with height set',
],
/* Max image area */
[
[ 4000, 4000 ],
[
'width' => 5000, 'height' => 5000,
'physicalWidth' => 4000, 'physicalHeight' => 4000,
'page' => 1, 'interlace' => false,
],
[ 'width' => 5000 ],
'Bigger than max image size but doesn\'t need scaling',
],
/* Max interlace image area */
[
[ 4000, 4000 ],
[
'width' => 5000, 'height' => 5000,
'physicalWidth' => 4000, 'physicalHeight' => 4000,
'page' => 1, 'interlace' => false,
],
[ 'width' => 5000, 'interlace' => true ],
'Interlace bigger than max interlace area',
],
];
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
}
/**
* @covers BitmapHandler::doTransform
*/
public function testTooBigImage() {
$file = new FakeDimensionFile( [ 4000, 4000 ] );
$handler = new BitmapHandler;
$params = [ 'width' => '3700' ]; // Still bigger than max size.
$this->assertEquals( TransformTooBigImageAreaError::class,
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
}
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
/**
* @covers BitmapHandler::doTransform
*/
public function testTooBigMustRenderImage() {
$file = new FakeDimensionFile( [ 4000, 4000 ] );
$file->mustRender = true;
$handler = new BitmapHandler;
$params = [ 'width' => '5000' ]; // Still bigger than max size.
$this->assertEquals( TransformTooBigImageAreaError::class,
get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
}
/**
* @covers BitmapHandler::getImageArea
*/
public function testImageArea() {
$file = new FakeDimensionFile( [ 7, 9 ] );
$handler = new BitmapHandler;
$this->assertEquals( 63, $handler->getImageArea( $file ) );
}
}