summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/GlobalFunctions/wfThumbIsStandardTest.php
blob: 448250a681c4eb4a0a69248a5653a937d5a02264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php

/**
 * @group GlobalFunctions
 * @covers ::wfThumbIsStandard
 */
class WfThumbIsStandardTest extends MediaWikiTestCase {

	protected function setUp() {
		parent::setUp();

		$this->setMwGlobals( array(
			'wgThumbLimits' => array(
				100,
				401
			),
			'wgImageLimits' => array(
				array( 300, 225 ),
				array( 800, 600 ),
			),
			'wgMediaHandlers' => array(
				'unknown/unknown' => 'MockBitmapHandler',
			),
		) );
	}

	public static function provideThumbParams() {
		return array(
			// Thumb limits
			array(
				'Standard thumb width',
				true,
				array( 'width' => 100 ),
			),
			array(
				'Standard thumb width',
				true,
				array( 'width' => 401 ),
			),
			// wfThumbIsStandard should match Linker::processResponsiveImages
			// in its rounding behaviour.
			array(
				'Standard thumb width (HiDPI 1.5x) - incorrect rounding',
				false,
				array( 'width' => 601 ),
			),
			array(
				'Standard thumb width (HiDPI 1.5x)',
				true,
				array( 'width' => 602 ),
			),
			array(
				'Standard thumb width (HiDPI 2x)',
				true,
				array( 'width' => 802 ),
			),
			array(
				'Non-standard thumb width',
				false,
				array( 'width' => 300 ),
			),
			// Image limits
			// Note: Image limits are measured as pairs. Individual values
			// may be non-standard based on the aspect ratio.
			array(
				'Standard image width/height pair',
				true,
				array( 'width' => 250, 'height' => 225 ),
			),
			array(
				'Standard image width/height pair',
				true,
				array( 'width' => 667, 'height' => 600 ),
			),
			array(
				'Standard image width where image does not fit aspect ratio',
				false,
				array( 'width' => 300 ),
			),
			array(
				'Implicit width from image width/height pair aspect ratio fit',
				true,
				// 2000x1800 fit inside 300x225 makes w=250
				array( 'width' => 250 ),
			),
			array(
				'Height-only is always non-standard',
				false,
				array( 'height' => 225 ),
			),
		);
	}

	/**
	 * @dataProvider provideThumbParams
	 */
	public function testIsStandard( $message, $expected, $params ) {
		$this->assertSame(
			$expected,
			wfThumbIsStandard( new FakeDimensionFile( array( 2000, 1800 ) ), $params ),
			$message
		);
	}
}