2b30cfa5ebf2c537e089d93058ee09d55d7f8228
[lhc/web/wiklou.git] / tests / phpunit / includes / page / ImagePageTest.php
1 <?php
2 class ImagePageTest extends MediaWikiMediaTestCase {
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
23 /**
24 * @dataProvider providerGetDisplayWidthHeight
25 * @param array $dim Array [maxWidth, maxHeight, width, height]
26 * @param array $expected Array [width, height] The width and height we expect to display at
27 */
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
38 function providerGetDisplayWidthHeight() {
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
67 /**
68 * @dataProvider providerGetThumbSizes
69 * @param string $filename
70 * @param int $expectedNumberThumbs How many thumbnails to show
71 */
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 }