Merge "Export: Use BCP 47 language code for attribute xml:lang"
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfThumbIsStandardTest.php
1 <?php
2
3 /**
4 * @group GlobalFunctions
5 * @covers ::wfThumbIsStandard
6 */
7 class WfThumbIsStandardTest extends MediaWikiTestCase {
8
9 protected function setUp() {
10 parent::setUp();
11
12 $this->setMwGlobals( [
13 'wgThumbLimits' => [
14 100,
15 401
16 ],
17 'wgImageLimits' => [
18 [ 300, 225 ],
19 [ 800, 600 ],
20 ],
21 ] );
22 }
23
24 public static function provideThumbParams() {
25 return [
26 // Thumb limits
27 [
28 'Standard thumb width',
29 true,
30 [ 'width' => 100 ],
31 ],
32 [
33 'Standard thumb width',
34 true,
35 [ 'width' => 401 ],
36 ],
37 // wfThumbIsStandard should match Linker::processResponsiveImages
38 // in its rounding behaviour.
39 [
40 'Standard thumb width (HiDPI 1.5x) - incorrect rounding',
41 false,
42 [ 'width' => 601 ],
43 ],
44 [
45 'Standard thumb width (HiDPI 1.5x)',
46 true,
47 [ 'width' => 602 ],
48 ],
49 [
50 'Standard thumb width (HiDPI 2x)',
51 true,
52 [ 'width' => 802 ],
53 ],
54 [
55 'Non-standard thumb width',
56 false,
57 [ 'width' => 300 ],
58 ],
59 // Image limits
60 // Note: Image limits are measured as pairs. Individual values
61 // may be non-standard based on the aspect ratio.
62 [
63 'Standard image width/height pair',
64 true,
65 [ 'width' => 250, 'height' => 225 ],
66 ],
67 [
68 'Standard image width/height pair',
69 true,
70 [ 'width' => 667, 'height' => 600 ],
71 ],
72 [
73 'Standard image width where image does not fit aspect ratio',
74 false,
75 [ 'width' => 300 ],
76 ],
77 [
78 'Implicit width from image width/height pair aspect ratio fit',
79 true,
80 // 2000x1800 fit inside 300x225 makes w=250
81 [ 'width' => 250 ],
82 ],
83 [
84 'Height-only is always non-standard',
85 false,
86 [ 'height' => 225 ],
87 ],
88 ];
89 }
90
91 /**
92 * @dataProvider provideThumbParams
93 */
94 public function testIsStandard( $message, $expected, $params ) {
95 $this->setService( 'MediaHandlerFactory', new MockMediaHandlerFactory() );
96 $this->assertSame(
97 $expected,
98 wfThumbIsStandard( new FakeDimensionFile( [ 2000, 1800 ] ), $params ),
99 $message
100 );
101 }
102 }