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