MediaWiki REL1_31
wfThumbIsStandardTest.php
Go to the documentation of this file.
1<?php
2
4
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
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}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfThumbIsStandard(File $file, array $params)
Returns true if these thumbnail parameters match one that MediaWiki requests from file description pa...
Class to construct MediaHandler objects.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
MediaWikiServices is the service locator for the application scope of MediaWiki.
GlobalFunctions wfThumbIsStandard.
testIsStandard( $message, $expected, $params)
provideThumbParams
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$params