MediaWiki
REL1_21
|
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 00017 function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) { 00018 $file = new FakeDimensionFile( $fileDimensions ); 00019 $handler = new BitmapHandler; 00020 $valid = $handler->normaliseParams( $file, $params ); 00021 $this->assertTrue( $valid ); 00022 $this->assertEquals( $expectedParams, $params, $msg ); 00023 } 00024 00025 function provideNormaliseParams() { 00026 return array( 00027 /* Regular resize operations */ 00028 array( 00029 array( 1024, 768 ), 00030 array( 00031 'width' => 512, 'height' => 384, 00032 'physicalWidth' => 512, 'physicalHeight' => 384, 00033 'page' => 1, 00034 ), 00035 array( 'width' => 512 ), 00036 'Resizing with width set', 00037 ), 00038 array( 00039 array( 1024, 768 ), 00040 array( 00041 'width' => 512, 'height' => 384, 00042 'physicalWidth' => 512, 'physicalHeight' => 384, 00043 'page' => 1, 00044 ), 00045 array( 'width' => 512, 'height' => 768 ), 00046 'Resizing with height set too high', 00047 ), 00048 array( 00049 array( 1024, 768 ), 00050 array( 00051 'width' => 512, 'height' => 384, 00052 'physicalWidth' => 512, 'physicalHeight' => 384, 00053 'page' => 1, 00054 ), 00055 array( 'width' => 1024, 'height' => 384 ), 00056 'Resizing with height set', 00057 ), 00058 00059 /* Very tall images */ 00060 array( 00061 array( 1000, 100 ), 00062 array( 00063 'width' => 5, 'height' => 1, 00064 'physicalWidth' => 5, 'physicalHeight' => 1, 00065 'page' => 1, 00066 ), 00067 array( 'width' => 5 ), 00068 'Very wide image', 00069 ), 00070 00071 array( 00072 array( 100, 1000 ), 00073 array( 00074 'width' => 1, 'height' => 10, 00075 'physicalWidth' => 1, 'physicalHeight' => 10, 00076 'page' => 1, 00077 ), 00078 array( 'width' => 1 ), 00079 'Very high image', 00080 ), 00081 array( 00082 array( 100, 1000 ), 00083 array( 00084 'width' => 1, 'height' => 5, 00085 'physicalWidth' => 1, 'physicalHeight' => 10, 00086 'page' => 1, 00087 ), 00088 array( 'width' => 10, 'height' => 5 ), 00089 'Very high image with height set', 00090 ), 00091 /* Max image area */ 00092 array( 00093 array( 4000, 4000 ), 00094 array( 00095 'width' => 5000, 'height' => 5000, 00096 'physicalWidth' => 4000, 'physicalHeight' => 4000, 00097 'page' => 1, 00098 ), 00099 array( 'width' => 5000 ), 00100 'Bigger than max image size but doesn\'t need scaling', 00101 ), 00102 ); 00103 } 00104 00105 function testTooBigImage() { 00106 $file = new FakeDimensionFile( array( 4000, 4000 ) ); 00107 $handler = new BitmapHandler; 00108 $params = array( 'width' => '3700' ); // Still bigger than max size. 00109 $this->assertEquals( 'TransformParameterError', 00110 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) ); 00111 } 00112 00113 function testTooBigMustRenderImage() { 00114 $file = new FakeDimensionFile( array( 4000, 4000 ) ); 00115 $file->mustRender = true; 00116 $handler = new BitmapHandler; 00117 $params = array( 'width' => '5000' ); // Still bigger than max size. 00118 $this->assertEquals( 'TransformParameterError', 00119 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) ); 00120 } 00121 00122 function testImageArea() { 00123 $file = new FakeDimensionFile( array( 7, 9 ) ); 00124 $handler = new BitmapHandler; 00125 $this->assertEquals( 63, $handler->getImageArea( $file ) ); 00126 } 00127 } 00128 00129 class FakeDimensionFile extends File { 00130 public $mustRender = false; 00131 00132 public function __construct( $dimensions ) { 00133 parent::__construct( Title::makeTitle( NS_FILE, 'Test' ), 00134 new NullRepo( null ) ); 00135 00136 $this->dimensions = $dimensions; 00137 } 00138 00139 public function getWidth( $page = 1 ) { 00140 return $this->dimensions[0]; 00141 } 00142 00143 public function getHeight( $page = 1 ) { 00144 return $this->dimensions[1]; 00145 } 00146 00147 public function mustRender() { 00148 return $this->mustRender; 00149 } 00150 00151 public function getPath() { 00152 return ''; 00153 } 00154 }