Merge "Revert "Hide HHVM tag on Special:{Contributions,RecentChanges,...}""
[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', array(
6 array( 320, 240 ),
7 array( 640, 480 ),
8 array( 800, 600 ),
9 array( 1024, 768 ),
10 array( 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 array(
40 array(
41 array( 1024.0, 768.0, 600.0, 600.0 ),
42 array( 600.0, 600.0 )
43 ),
44 array(
45 array( 1024.0, 768.0, 1600.0, 600.0 ),
46 array( 1024.0, 384.0 )
47 ),
48 array(
49 array( 1024.0, 768.0, 1024.0, 768.0 ),
50 array( 1024.0, 768.0 )
51 ),
52 array(
53 array( 1024.0, 768.0, 800.0, 1000.0 ),
54 array( 614.0, 768.0 )
55 ),
56 array(
57 array( 1024.0, 768.0, 0, 1000 ),
58 array( 0, 0 )
59 ),
60 array(
61 array( 1024.0, 768.0, 2000, 0 ),
62 array( 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 array(
84 array( 'animated.gif', 2 ),
85 array( 'Toll_Texas_1.svg', 1 ),
86 array( '80x60-Greyscale.xcf', 1 ),
87 array( 'jpeg-comment-binary.jpg', 2 ),
88 );
89 }
90 }