MediaWiki
REL1_22
|
00001 <?php 00002 00003 class MediaHandlerTest extends MediaWikiTestCase { 00004 00009 public function testFitBoxWidth() { 00010 $vals = array( 00011 array( 00012 'width' => 50, 00013 'height' => 50, 00014 'tests' => array( 00015 50 => 50, 00016 17 => 17, 00017 18 => 18 ) ), 00018 array( 00019 'width' => 366, 00020 'height' => 300, 00021 'tests' => array( 00022 50 => 61, 00023 17 => 21, 00024 18 => 22 ) ), 00025 array( 00026 'width' => 300, 00027 'height' => 366, 00028 'tests' => array( 00029 50 => 41, 00030 17 => 14, 00031 18 => 15 ) ), 00032 array( 00033 'width' => 100, 00034 'height' => 400, 00035 'tests' => array( 00036 50 => 12, 00037 17 => 4, 00038 18 => 4 ) ) ); 00039 foreach ( $vals as $row ) { 00040 $tests = $row['tests']; 00041 $height = $row['height']; 00042 $width = $row['width']; 00043 foreach ( $tests as $max => $expected ) { 00044 $y = round( $expected * $height / $width ); 00045 $result = MediaHandler::fitBoxWidth( $width, $height, $max ); 00046 $y2 = round( $result * $height / $width ); 00047 $this->assertEquals( $expected, 00048 $result, 00049 "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" ); 00050 } 00051 } 00052 } 00053 }