Merge "Change php extract() to explicit code"
[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 * @covers ImagePage::getDisplayWidthHeight
25 * @dataProvider providerGetDisplayWidthHeight
26 * @param array $dim Array [maxWidth, maxHeight, width, height]
27 * @param array $expected Array [width, height] The width and height we expect to display at
28 */
29 function testGetDisplayWidthHeight( $dim, $expected ) {
30 $iPage = $this->getImagePage( 'animated.gif' );
31 $reflection = new ReflectionClass( $iPage );
32 $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
33 $reflMethod->setAccessible( true );
34
35 $actual = $reflMethod->invoke( $iPage, $dim[0], $dim[1], $dim[2], $dim[3] );
36 $this->assertEquals( $actual, $expected );
37 }
38
39 function providerGetDisplayWidthHeight() {
40 return [
41 [
42 [ 1024.0, 768.0, 600.0, 600.0 ],
43 [ 600.0, 600.0 ]
44 ],
45 [
46 [ 1024.0, 768.0, 1600.0, 600.0 ],
47 [ 1024.0, 384.0 ]
48 ],
49 [
50 [ 1024.0, 768.0, 1024.0, 768.0 ],
51 [ 1024.0, 768.0 ]
52 ],
53 [
54 [ 1024.0, 768.0, 800.0, 1000.0 ],
55 [ 614.0, 768.0 ]
56 ],
57 [
58 [ 1024.0, 768.0, 0, 1000 ],
59 [ 0, 0 ]
60 ],
61 [
62 [ 1024.0, 768.0, 2000, 0 ],
63 [ 0, 0 ]
64 ],
65 ];
66 }
67
68 /**
69 * @covers ImagePage::getThumbSizes
70 * @dataProvider providerGetThumbSizes
71 * @param string $filename
72 * @param int $expectedNumberThumbs How many thumbnails to show
73 */
74 function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
75 $iPage = $this->getImagePage( $filename );
76 $reflection = new ReflectionClass( $iPage );
77 $reflMethod = $reflection->getMethod( 'getThumbSizes' );
78 $reflMethod->setAccessible( true );
79
80 $actual = $reflMethod->invoke( $iPage, 545, 700 );
81 $this->assertEquals( count( $actual ), $expectedNumberThumbs );
82 }
83
84 function providerGetThumbSizes() {
85 return [
86 [ 'animated.gif', 2 ],
87 [ 'Toll_Texas_1.svg', 1 ],
88 [ '80x60-Greyscale.xcf', 1 ],
89 [ 'jpeg-comment-binary.jpg', 2 ],
90 ];
91 }
92 }