Merge "Run the ImagePageShowTOC hook before adding the 'metadata' link"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / MediaHandlerTest.php
1 <?php
2
3 /**
4 * @group Media
5 */
6 class MediaHandlerTest extends MediaWikiTestCase {
7
8 /**
9 * @covers MediaHandler::fitBoxWidth
10 *
11 * @dataProvider provideTestFitBoxWidth
12 */
13 public function testFitBoxWidth( $width, $height, $max, $expected ) {
14 $y = round( $expected * $height / $width );
15 $result = MediaHandler::fitBoxWidth( $width, $height, $max );
16 $y2 = round( $result * $height / $width );
17 $this->assertEquals( $expected,
18 $result,
19 "($width, $height, $max) wanted: {$expected}x$y, got: {z$result}x$y2" );
20 }
21
22 public function provideTestFitBoxWidth() {
23 return array_merge(
24 $this->provideTestFitBoxWidthSingle( 50, 50, array(
25 50 => 50,
26 17 => 17,
27 18 => 18 )
28 ),
29 $this->provideTestFitBoxWidthSingle( 366, 300, array(
30 50 => 61,
31 17 => 21,
32 18 => 22 )
33 ),
34 $this->provideTestFitBoxWidthSingle( 300, 366, array(
35 50 => 41,
36 17 => 14,
37 18 => 15 )
38 ),
39 $this->provideTestFitBoxWidthSingle( 100, 400, array(
40 50 => 12,
41 17 => 4,
42 18 => 4 )
43 )
44 );
45 }
46
47 private function provideTestFitBoxWidthSingle( $width, $height, $tests ) {
48 $result = array();
49 foreach ( $tests as $max => $expected ) {
50 $result[] = array( $width, $height, $max, $expected );
51 }
52 return $result;
53 }
54 }