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