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