MediaWiki
REL1_22
|
00001 <?php 00002 00003 class BitmapScalingTest extends MediaWikiTestCase { 00004 00005 protected function setUp() { 00006 parent::setUp(); 00007 00008 $this->setMwGlobals( array( 00009 'wgMaxImageArea' => 1.25e7, // 3500x3500 00010 'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering 00011 ) ); 00012 } 00013 00018 public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) { 00019 $file = new FakeDimensionFile( $fileDimensions ); 00020 $handler = new BitmapHandler; 00021 $valid = $handler->normaliseParams( $file, $params ); 00022 $this->assertTrue( $valid ); 00023 $this->assertEquals( $expectedParams, $params, $msg ); 00024 } 00025 00026 public static function provideNormaliseParams() { 00027 return array( 00028 /* Regular resize operations */ 00029 array( 00030 array( 1024, 768 ), 00031 array( 00032 'width' => 512, 'height' => 384, 00033 'physicalWidth' => 512, 'physicalHeight' => 384, 00034 'page' => 1, 00035 ), 00036 array( 'width' => 512 ), 00037 'Resizing with width set', 00038 ), 00039 array( 00040 array( 1024, 768 ), 00041 array( 00042 'width' => 512, 'height' => 384, 00043 'physicalWidth' => 512, 'physicalHeight' => 384, 00044 'page' => 1, 00045 ), 00046 array( 'width' => 512, 'height' => 768 ), 00047 'Resizing with height set too high', 00048 ), 00049 array( 00050 array( 1024, 768 ), 00051 array( 00052 'width' => 512, 'height' => 384, 00053 'physicalWidth' => 512, 'physicalHeight' => 384, 00054 'page' => 1, 00055 ), 00056 array( 'width' => 1024, 'height' => 384 ), 00057 'Resizing with height set', 00058 ), 00059 00060 /* Very tall images */ 00061 array( 00062 array( 1000, 100 ), 00063 array( 00064 'width' => 5, 'height' => 1, 00065 'physicalWidth' => 5, 'physicalHeight' => 1, 00066 'page' => 1, 00067 ), 00068 array( 'width' => 5 ), 00069 'Very wide image', 00070 ), 00071 00072 array( 00073 array( 100, 1000 ), 00074 array( 00075 'width' => 1, 'height' => 10, 00076 'physicalWidth' => 1, 'physicalHeight' => 10, 00077 'page' => 1, 00078 ), 00079 array( 'width' => 1 ), 00080 'Very high image', 00081 ), 00082 array( 00083 array( 100, 1000 ), 00084 array( 00085 'width' => 1, 'height' => 5, 00086 'physicalWidth' => 1, 'physicalHeight' => 10, 00087 'page' => 1, 00088 ), 00089 array( 'width' => 10, 'height' => 5 ), 00090 'Very high image with height set', 00091 ), 00092 /* Max image area */ 00093 array( 00094 array( 4000, 4000 ), 00095 array( 00096 'width' => 5000, 'height' => 5000, 00097 'physicalWidth' => 4000, 'physicalHeight' => 4000, 00098 'page' => 1, 00099 ), 00100 array( 'width' => 5000 ), 00101 'Bigger than max image size but doesn\'t need scaling', 00102 ), 00103 ); 00104 } 00105 00109 public function testTooBigImage() { 00110 $file = new FakeDimensionFile( array( 4000, 4000 ) ); 00111 $handler = new BitmapHandler; 00112 $params = array( 'width' => '3700' ); // Still bigger than max size. 00113 $this->assertEquals( 'TransformParameterError', 00114 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) ); 00115 } 00116 00120 public function testTooBigMustRenderImage() { 00121 $file = new FakeDimensionFile( array( 4000, 4000 ) ); 00122 $file->mustRender = true; 00123 $handler = new BitmapHandler; 00124 $params = array( 'width' => '5000' ); // Still bigger than max size. 00125 $this->assertEquals( 'TransformParameterError', 00126 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) ); 00127 } 00128 00132 public function testImageArea() { 00133 $file = new FakeDimensionFile( array( 7, 9 ) ); 00134 $handler = new BitmapHandler; 00135 $this->assertEquals( 63, $handler->getImageArea( $file ) ); 00136 } 00137 }