Merge "Add DROP INDEX support to DatabaseSqlite::replaceVars method"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / BitmapScalingTest.php
1 <?php
2
3 class BitmapScalingTest extends MediaWikiTestCase {
4
5 protected function setUp() {
6 parent::setUp();
7
8 $this->setMwGlobals( array(
9 'wgMaxImageArea' => 1.25e7, // 3500x3500
10 'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
11 ) );
12 }
13
14 /**
15 * @dataProvider provideNormaliseParams
16 * @covers BitmapHandler::normaliseParams
17 */
18 public function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
19 $file = new FakeDimensionFile( $fileDimensions );
20 $handler = new BitmapHandler;
21 $valid = $handler->normaliseParams( $file, $params );
22 $this->assertTrue( $valid );
23 $this->assertEquals( $expectedParams, $params, $msg );
24 }
25
26 public static function provideNormaliseParams() {
27 return array(
28 /* Regular resize operations */
29 array(
30 array( 1024, 768 ),
31 array(
32 'width' => 512, 'height' => 384,
33 'physicalWidth' => 512, 'physicalHeight' => 384,
34 'page' => 1,
35 ),
36 array( 'width' => 512 ),
37 'Resizing with width set',
38 ),
39 array(
40 array( 1024, 768 ),
41 array(
42 'width' => 512, 'height' => 384,
43 'physicalWidth' => 512, 'physicalHeight' => 384,
44 'page' => 1,
45 ),
46 array( 'width' => 512, 'height' => 768 ),
47 'Resizing with height set too high',
48 ),
49 array(
50 array( 1024, 768 ),
51 array(
52 'width' => 512, 'height' => 384,
53 'physicalWidth' => 512, 'physicalHeight' => 384,
54 'page' => 1,
55 ),
56 array( 'width' => 1024, 'height' => 384 ),
57 'Resizing with height set',
58 ),
59
60 /* Very tall images */
61 array(
62 array( 1000, 100 ),
63 array(
64 'width' => 5, 'height' => 1,
65 'physicalWidth' => 5, 'physicalHeight' => 1,
66 'page' => 1,
67 ),
68 array( 'width' => 5 ),
69 'Very wide image',
70 ),
71
72 array(
73 array( 100, 1000 ),
74 array(
75 'width' => 1, 'height' => 10,
76 'physicalWidth' => 1, 'physicalHeight' => 10,
77 'page' => 1,
78 ),
79 array( 'width' => 1 ),
80 'Very high image',
81 ),
82 array(
83 array( 100, 1000 ),
84 array(
85 'width' => 1, 'height' => 5,
86 'physicalWidth' => 1, 'physicalHeight' => 10,
87 'page' => 1,
88 ),
89 array( 'width' => 10, 'height' => 5 ),
90 'Very high image with height set',
91 ),
92 /* Max image area */
93 array(
94 array( 4000, 4000 ),
95 array(
96 'width' => 5000, 'height' => 5000,
97 'physicalWidth' => 4000, 'physicalHeight' => 4000,
98 'page' => 1,
99 ),
100 array( 'width' => 5000 ),
101 'Bigger than max image size but doesn\'t need scaling',
102 ),
103 );
104 }
105
106 /**
107 * @covers BitmapHandler::doTransform
108 */
109 public function testTooBigImage() {
110 $file = new FakeDimensionFile( array( 4000, 4000 ) );
111 $handler = new BitmapHandler;
112 $params = array( 'width' => '3700' ); // Still bigger than max size.
113 $this->assertEquals( 'TransformParameterError',
114 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
115 }
116
117 /**
118 * @covers BitmapHandler::doTransform
119 */
120 public function testTooBigMustRenderImage() {
121 $file = new FakeDimensionFile( array( 4000, 4000 ) );
122 $file->mustRender = true;
123 $handler = new BitmapHandler;
124 $params = array( 'width' => '5000' ); // Still bigger than max size.
125 $this->assertEquals( 'TransformParameterError',
126 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
127 }
128
129 /**
130 * @covers BitmapHandler::getImageArea
131 */
132 public function testImageArea() {
133 $file = new FakeDimensionFile( array( 7, 9 ) );
134 $handler = new BitmapHandler;
135 $this->assertEquals( 63, $handler->getImageArea( $file ) );
136 }
137 }