bca4b55a5f1584936a397a4e0291a22b3ba5d8e1
[lhc/web/wiklou.git] / tests / phpunit / includes / media / BitmapScalingTest.php
1 <?php
2
3 class BitmapScalingTest extends MediaWikiTestCase {
4 /**
5 * @dataProvider provideNormaliseParams
6 */
7 function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
8 $file = new FakeDimensionFile( $fileDimensions );
9 $handler = new BitmapHandler;
10 $handler->normaliseParams( $file, $params );
11 $this->assertEquals( $expectedParams, $params, $msg );
12 }
13
14 function provideNormaliseParams() {
15 return array(
16 /* Regular resize operations */
17 array(
18 array( 1024, 768 ),
19 array(
20 'width' => 512, 'height' => 384,
21 'physicalWidth' => 512, 'physicalHeight' => 384,
22 'page' => 1,
23 ),
24 array( 'width' => 512 ),
25 'Resizing with width set',
26 ),
27 array(
28 array( 1024, 768 ),
29 array(
30 'width' => 512, 'height' => 384,
31 'physicalWidth' => 512, 'physicalHeight' => 384,
32 'page' => 1,
33 ),
34 array( 'width' => 512, 'height' => 768 ),
35 'Resizing with height set too high',
36 ),
37 array(
38 array( 1024, 768 ),
39 array(
40 'width' => 512, 'height' => 384,
41 'physicalWidth' => 512, 'physicalHeight' => 384,
42 'page' => 1,
43 ),
44 array( 'width' => 1024, 'height' => 384 ),
45 'Resizing with height set',
46 ),
47
48 /* Very tall images */
49 array(
50 array( 1000, 100 ),
51 array(
52 'width' => 5, 'height' => 1,
53 'physicalWidth' => 5, 'physicalHeight' => 1,
54 'page' => 1,
55 ),
56 array( 'width' => 5 ),
57 'Very wide image',
58 ),
59
60 array(
61 array( 100, 1000 ),
62 array(
63 'width' => 1, 'height' => 10,
64 'physicalWidth' => 1, 'physicalHeight' => 10,
65 'page' => 1,
66 ),
67 array( 'width' => 1 ),
68 'Very high image',
69 ),
70 array(
71 array( 100, 1000 ),
72 array(
73 'width' => 1, 'height' => 5,
74 'physicalWidth' => 1, 'physicalHeight' => 10,
75 'page' => 1,
76 ),
77 array( 'width' => 10, 'height' => 5 ),
78 'Very high image with height set',
79 ),
80 );
81 }
82 }
83
84 class FakeDimensionFile extends File {
85 public function __construct( $dimensions ) {
86 parent::__construct( Title::makeTitle( NS_FILE, 'Test' ), null );
87
88 $this->dimensions = $dimensions;
89 }
90 public function getWidth( $page = 1 ) {
91 return $this->dimensions[0];
92 }
93 public function getHeight( $page = 1 ) {
94 return $this->dimensions[1];
95 }
96 }