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