MediaWiki  1.29.1
ImagePageTest.php
Go to the documentation of this file.
1 <?php
3 
4  function setUp() {
5  $this->setMwGlobals( 'wgImageLimits', [
6  [ 320, 240 ],
7  [ 640, 480 ],
8  [ 800, 600 ],
9  [ 1024, 768 ],
10  [ 1280, 1024 ]
11  ] );
12  parent::setUp();
13  }
14 
15  function getImagePage( $filename ) {
16  $title = Title::makeTitleSafe( NS_FILE, $filename );
17  $file = $this->dataFile( $filename );
18  $iPage = new ImagePage( $title );
19  $iPage->setFile( $file );
20  return $iPage;
21  }
22 
28  function testGetDisplayWidthHeight( $dim, $expected ) {
29  $iPage = $this->getImagePage( 'animated.gif' );
30  $reflection = new ReflectionClass( $iPage );
31  $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
32  $reflMethod->setAccessible( true );
33 
34  $actual = $reflMethod->invoke( $iPage, $dim[0], $dim[1], $dim[2], $dim[3] );
35  $this->assertEquals( $actual, $expected );
36  }
37 
39  return [
40  [
41  [ 1024.0, 768.0, 600.0, 600.0 ],
42  [ 600.0, 600.0 ]
43  ],
44  [
45  [ 1024.0, 768.0, 1600.0, 600.0 ],
46  [ 1024.0, 384.0 ]
47  ],
48  [
49  [ 1024.0, 768.0, 1024.0, 768.0 ],
50  [ 1024.0, 768.0 ]
51  ],
52  [
53  [ 1024.0, 768.0, 800.0, 1000.0 ],
54  [ 614.0, 768.0 ]
55  ],
56  [
57  [ 1024.0, 768.0, 0, 1000 ],
58  [ 0, 0 ]
59  ],
60  [
61  [ 1024.0, 768.0, 2000, 0 ],
62  [ 0, 0 ]
63  ],
64  ];
65  }
66 
72  function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
73  $iPage = $this->getImagePage( $filename );
74  $reflection = new ReflectionClass( $iPage );
75  $reflMethod = $reflection->getMethod( 'getThumbSizes' );
76  $reflMethod->setAccessible( true );
77 
78  $actual = $reflMethod->invoke( $iPage, 545, 700 );
79  $this->assertEquals( count( $actual ), $expectedNumberThumbs );
80  }
81 
82  function providerGetThumbSizes() {
83  return [
84  [ 'animated.gif', 2 ],
85  [ 'Toll_Texas_1.svg', 1 ],
86  [ '80x60-Greyscale.xcf', 1 ],
87  [ 'jpeg-comment-binary.jpg', 2 ],
88  ];
89  }
90 }
ImagePageTest
Definition: ImagePageTest.php:2
captcha-old.count
count
Definition: captcha-old.py:225
NS_FILE
const NS_FILE
Definition: Defines.php:68
ImagePage
Class for viewing MediaWiki file description pages.
Definition: ImagePage.php:30
ImagePageTest\providerGetDisplayWidthHeight
providerGetDisplayWidthHeight()
Definition: ImagePageTest.php:38
php
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:35
MediaWikiMediaTestCase
Specificly for testing Media handlers.
Definition: MediaWikiMediaTestCase.php:5
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:658
ImagePageTest\providerGetThumbSizes
providerGetThumbSizes()
Definition: ImagePageTest.php:82
MediaWikiMediaTestCase\dataFile
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
Definition: MediaWikiMediaTestCase.php:76
ImagePageTest\testGetDisplayWidthHeight
testGetDisplayWidthHeight( $dim, $expected)
providerGetDisplayWidthHeight
Definition: ImagePageTest.php:28
ImagePageTest\testGetThumbSizes
testGetThumbSizes( $filename, $expectedNumberThumbs)
providerGetThumbSizes
Definition: ImagePageTest.php:72
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:538
ImagePageTest\setUp
setUp()
Definition: ImagePageTest.php:4
ImagePageTest\getImagePage
getImagePage( $filename)
Definition: ImagePageTest.php:15