Merge "Use $wgUser in ResourceLoaderUserGroupsModule when possible."
[lhc/web/wiklou.git] / tests / phpunit / includes / media / MediaHandlerTest.php
1 <?php
2
3 class MediaHandlerTest extends MediaWikiTestCase {
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 $tests = $row['tests'];
36 $height = $row['height'];
37 $width = $row['width'];
38 foreach ( $tests as $max => $expected ) {
39 $y = round( $expected * $height / $width );
40 $result = MediaHandler::fitBoxWidth( $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