MediaWiki REL1_33
ImagePageTest.php
Go to the documentation of this file.
1<?php
2
4
6
7 public function setUp() {
8 $this->setMwGlobals( 'wgImageLimits', [
9 [ 320, 240 ],
10 [ 640, 480 ],
11 [ 800, 600 ],
12 [ 1024, 768 ],
13 [ 1280, 1024 ]
14 ] );
15 parent::setUp();
16 }
17
18 public function getImagePage( $filename ) {
19 $title = Title::makeTitleSafe( NS_FILE, $filename );
20 $file = $this->dataFile( $filename );
21 $iPage = new ImagePage( $title );
22 $iPage->setFile( $file );
23 return $iPage;
24 }
25
32 public function testGetDisplayWidthHeight( $dim, $expected ) {
33 $iPage = $this->getImagePage( 'animated.gif' );
34 $reflection = new ReflectionClass( $iPage );
35 $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
36 $reflMethod->setAccessible( true );
37
38 $actual = $reflMethod->invoke( $iPage, $dim[0], $dim[1], $dim[2], $dim[3] );
39 $this->assertEquals( $actual, $expected );
40 }
41
43 return [
44 [
45 [ 1024.0, 768.0, 600.0, 600.0 ],
46 [ 600.0, 600.0 ]
47 ],
48 [
49 [ 1024.0, 768.0, 1600.0, 600.0 ],
50 [ 1024.0, 384.0 ]
51 ],
52 [
53 [ 1024.0, 768.0, 1024.0, 768.0 ],
54 [ 1024.0, 768.0 ]
55 ],
56 [
57 [ 1024.0, 768.0, 800.0, 1000.0 ],
58 [ 614.0, 768.0 ]
59 ],
60 [
61 [ 1024.0, 768.0, 0, 1000 ],
62 [ 0, 0 ]
63 ],
64 [
65 [ 1024.0, 768.0, 2000, 0 ],
66 [ 0, 0 ]
67 ],
68 ];
69 }
70
77 public function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
78 $iPage = $this->getImagePage( $filename );
79 $reflection = new ReflectionClass( $iPage );
80 $reflMethod = $reflection->getMethod( 'getThumbSizes' );
81 $reflMethod->setAccessible( true );
82
83 $actual = $reflMethod->invoke( $iPage, 545, 700 );
84 $this->assertEquals( count( $actual ), $expectedNumberThumbs );
85 }
86
87 public function providerGetThumbSizes() {
88 return [
89 [ 'animated.gif', 2 ],
90 [ 'Toll_Texas_1.svg', 1 ],
91 [ '80x60-Greyscale.xcf', 1 ],
92 [ 'jpeg-comment-binary.jpg', 2 ],
93 ];
94 }
95
104 public function testGetLanguageForRendering( $expected = null, $wikiLangCode, $lang = null ) {
105 $params = [];
106 if ( $lang !== null ) {
107 $params['lang'] = $lang;
108 }
110 $this->setMwGlobals( 'wgLanguageCode', $wikiLangCode );
111
112 $page = $this->getImagePage( 'translated.svg' );
113 $page = TestingAccessWrapper::newFromObject( $page );
114
116 $result = $page->getLanguageForRendering( $request, $page->getDisplayedFile() );
117 $this->assertEquals( $expected, $result );
118 }
119
121 return [
122 [ 'ru', 'ru' ],
123 [ 'ru', 'ru', 'ru' ],
124 [ null, 'en' ],
125 [ null, 'fr' ],
126 [ null, 'en', 'en' ],
127 [ null, 'fr', 'fr' ],
128 [ null, 'ru', 'en' ],
129 [ 'de', 'ru', 'de' ],
130 ];
131 }
132}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
WebRequest clone which takes values from a provided array.
testGetThumbSizes( $filename, $expectedNumberThumbs)
ImagePage::getThumbSizes providerGetThumbSizes.
testGetDisplayWidthHeight( $dim, $expected)
ImagePage::getDisplayWidthHeight providerGetDisplayWidthHeight.
testGetLanguageForRendering( $expected=null, $wikiLangCode, $lang=null)
ImagePage::getLanguageForRendering() provideGetLanguageForRendering.
providerGetDisplayWidthHeight()
getImagePage( $filename)
Class for viewing MediaWiki file description pages.
Definition ImagePage.php:31
Specificly for testing Media handlers.
dataFile( $name, $type=false)
Utility function: Get a new file object for a file on disk but not actually in db.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2843
const NS_FILE
Definition Defines.php:79
$params
if(!isset( $args[0])) $lang