f06bc88c769c704682b7ae971a42d851ae8ca777
[lhc/web/wiklou.git] / tests / ImageFunctionsTest.php
1 <?php
2
3 require_once( 'ImageFunctions.php' );
4
5 class ImageFunctionsTest extends PHPUnit_Framework_TestCase {
6 function testFitBoxWidth() {
7 $vals = array(
8 array(
9 'width' => 50,
10 'height' => 50,
11 'tests' => array(
12 50 => 50,
13 17 => 17,
14 18 => 18 ) ),
15 array(
16 'width' => 366,
17 'height' => 300,
18 'tests' => array(
19 50 => 61,
20 17 => 21,
21 18 => 22 ) ),
22 array(
23 'width' => 300,
24 'height' => 366,
25 'tests' => array(
26 50 => 41,
27 17 => 14,
28 18 => 15 ) ),
29 array(
30 'width' => 100,
31 'height' => 400,
32 'tests' => array(
33 50 => 12,
34 17 => 4,
35 18 => 4 ) ) );
36 foreach( $vals as $row ) {
37 extract( $row );
38 foreach( $tests as $max => $expected ) {
39 $y = round( $expected * $height / $width );
40 $result = wfFitBoxWidth( $width, $height, $max );
41 $y2 = round( $result * $height / $width );
42 $this->assertEquals( $expected,
43 $result,
44 "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" );
45 }
46 }
47 }
48 }
49
50