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