Merge "rdbms: implement IDatabase::serverIsReadOnly() for sqlite/mssql"
[lhc/web/wiklou.git] / tests / phpunit / includes / page / ImagePageTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 class ImagePageTest extends MediaWikiMediaTestCase {
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
26 /**
27 * @covers ImagePage::getDisplayWidthHeight
28 * @dataProvider providerGetDisplayWidthHeight
29 * @param array $dim Array [maxWidth, maxHeight, width, height]
30 * @param array $expected Array [width, height] The width and height we expect to display at
31 */
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
42 public function providerGetDisplayWidthHeight() {
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
71 /**
72 * @covers ImagePage::getThumbSizes
73 * @dataProvider providerGetThumbSizes
74 * @param string $filename
75 * @param int $expectedNumberThumbs How many thumbnails to show
76 */
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
96 /**
97 * @covers ImagePage::getLanguageForRendering()
98 * @dataProvider provideGetLanguageForRendering
99 *
100 * @param string|null $expected Expected language code
101 * @param string $wikiLangCode Wiki language code
102 * @param string|null $lang lang=... URL parameter
103 */
104 public function testGetLanguageForRendering( $expected = null, $wikiLangCode, $lang = null ) {
105 $params = [];
106 if ( $lang !== null ) {
107 $params['lang'] = $lang;
108 }
109 $request = new FauxRequest( $params );
110 $this->setMwGlobals( 'wgLanguageCode', $wikiLangCode );
111
112 $page = $this->getImagePage( 'translated.svg' );
113 $page = TestingAccessWrapper::newFromObject( $page );
114
115 /** @var ImagePage $page */
116 $result = $page->getLanguageForRendering( $request, $page->getDisplayedFile() );
117 $this->assertEquals( $expected, $result );
118 }
119
120 public function provideGetLanguageForRendering() {
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 }