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