6 class MediaHandlerTest
extends MediaWikiTestCase
{
9 * @covers MediaHandler::fitBoxWidth
11 * @dataProvider provideTestFitBoxWidth
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,
19 "($width, $height, $max) wanted: {$expected}x$y, got: {z$result}x$y2" );
22 public static function provideTestFitBoxWidth() {
24 static::generateTestFitBoxWidthData( 50, 50, [
29 static::generateTestFitBoxWidthData( 366, 300, [
34 static::generateTestFitBoxWidthData( 300, 366, [
39 static::generateTestFitBoxWidthData( 100, 400, [
48 * Generate single test cases by combining the dimensions and tests contents
51 * [$width, $height, $max, $expected],
52 * [$width, $height, $max2, $expected2], ...
54 * $width, $height, { $max => $expected, $max2 => $expected2, ... }
58 * @param array $tests associative array of $max => $expected values
61 private static function generateTestFitBoxWidthData( $width, $height, $tests ) {
63 foreach ( $tests as $max => $expected ) {
64 $result[] = [ $width, $height, $max, $expected ];
70 * @covers MediaHandler::getPageRangesByDimensions
72 * @dataProvider provideTestGetPageRangesByDimensions
74 public function testGetPageRangesByDimensions( $pagesByDimensions, $expected ) {
75 $this->assertEquals( $expected, MediaHandler
::getPageRangesByDimensions( $pagesByDimensions ) );
78 public static function provideTestGetPageRangesByDimensions() {
80 [ [ '123x456' => [ 1 ] ], '123x456:1' ],
81 [ [ '123x456' => [ 1, 2 ] ], '123x456:1-2' ],
82 [ [ '123x456' => [ 1, 2, 3 ] ], '123x456:1-3' ],
83 [ [ '123x456' => [ 1, 2, 3, 5 ] ], '123x456:1-3,5' ],
84 [ [ '123x456' => [ 1, 3 ] ], '123x456:1,3' ],
85 [ [ '123x456' => [ 1, 2, 3, 5, 6, 7 ] ], '123x456:1-3,5-7' ],
86 [ [ '123x456' => [ 1, 2, 3, 5, 6, 7 ],
87 '789x789' => [ 4, 8, 9 ] ], '123x456:1-3,5-7/789x789:4,8-9'