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 ];