5957bec54a89ee982a205ff3f9b5d0fdaed68fc7
[lhc/web/wiklou.git] / tests / ImageTest.php
1 <?php
2
3 require_once( 'PHPUnit.php' );
4 require_once( '../includes/Defines.php' );
5 #require_once( '../includes/Profiling.php' );
6 require_once( '../includes/GlobalFunctions.php' );
7 require_once( '../includes/Image.php' );
8 require_once( '../includes/ImageFunctions.php' );
9
10 class ImageTest extends PHPUnit_TestCase {
11 function ImageTest( $name ) {
12 $this->PHPUnit_TestCase( $name );
13 }
14
15 function setUp() {
16 }
17
18 function tearDown() {
19 }
20
21 function testFitBoxWidth() {
22 $vals = array(
23 array(
24 'width' => 50,
25 'height' => 50,
26 'tests' => array(
27 50 => 50,
28 17 => 17,
29 18 => 18 ) ),
30 array(
31 'width' => 366,
32 'height' => 300,
33 'tests' => array(
34 50 => 61,
35 17 => 21,
36 18 => 22 ) ),
37 array(
38 'width' => 300,
39 'height' => 366,
40 'tests' => array(
41 50 => 41,
42 17 => 14,
43 18 => 15 ) ),
44 array(
45 'width' => 100,
46 'height' => 400,
47 'tests' => array(
48 50 => 12,
49 17 => 4,
50 18 => 4 ) ) );
51 foreach( $vals as $row ) {
52 extract( $row );
53 foreach( $tests as $max => $expected ) {
54 $y = round( $expected * $height / $width );
55 $result = wfFitBoxWidth( $width, $height, $max );
56 $y2 = round( $result * $height / $width );
57 $this->assertEquals( $expected,
58 $result,
59 "($width, $height, $max) wanted: {$expected}x$y, got: {$result}x$y2" );
60 }
61 }
62 }
63
64 /* TODO: many more! */
65 }
66
67 ?>