00001 <?php 00002 00003 class ImageFunctionsTest extends PHPUnit_Framework_TestCase { 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 extract( $row ); 00036 foreach( $tests as $max => $expected ) { 00037 $y = round( $expected * $height / $width ); 00038 $result = wfFitBoxWidth( $width, $height, $max ); 00039 $y2 = round( $result * $height / $width ); 00040 $this->assertEquals( $expected, 00041 $result, 00042 "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" ); 00043 } 00044 } 00045 } 00046 } 00047 00048