Make partial dates in XMP not have the ommitted fields fulled out to 1's (reported...
[lhc/web/wiklou.git] / tests / phpunit / includes / media / BitmapScalingTest.php
1 <?php
2
3 class BitmapScalingTest extends MediaWikiTestCase {
4
5 function setUp() {
6 global $wgMaxImageArea;
7 $this->oldMaxImageArea = $wgMaxImageArea;
8 $wgMaxImageArea = 1.25e7; // 3500x3500
9 }
10 function tearDown() {
11 global $wgMaxImageArea;
12 $wgMaxImageArea = $this->oldMaxImageArea;
13 }
14 /**
15 * @dataProvider provideNormaliseParams
16 */
17 function testNormaliseParams( $fileDimensions, $expectedParams, $params, $msg ) {
18 $file = new FakeDimensionFile( $fileDimensions );
19 $handler = new BitmapHandler;
20 $valid = $handler->normaliseParams( $file, $params );
21 $this->assertTrue( $valid );
22 $this->assertEquals( $expectedParams, $params, $msg );
23 }
24
25 function provideNormaliseParams() {
26 return array(
27 /* Regular resize operations */
28 array(
29 array( 1024, 768 ),
30 array(
31 'width' => 512, 'height' => 384,
32 'physicalWidth' => 512, 'physicalHeight' => 384,
33 'page' => 1,
34 ),
35 array( 'width' => 512 ),
36 'Resizing with width set',
37 ),
38 array(
39 array( 1024, 768 ),
40 array(
41 'width' => 512, 'height' => 384,
42 'physicalWidth' => 512, 'physicalHeight' => 384,
43 'page' => 1,
44 ),
45 array( 'width' => 512, 'height' => 768 ),
46 'Resizing with height set too high',
47 ),
48 array(
49 array( 1024, 768 ),
50 array(
51 'width' => 512, 'height' => 384,
52 'physicalWidth' => 512, 'physicalHeight' => 384,
53 'page' => 1,
54 ),
55 array( 'width' => 1024, 'height' => 384 ),
56 'Resizing with height set',
57 ),
58
59 /* Very tall images */
60 array(
61 array( 1000, 100 ),
62 array(
63 'width' => 5, 'height' => 1,
64 'physicalWidth' => 5, 'physicalHeight' => 1,
65 'page' => 1,
66 ),
67 array( 'width' => 5 ),
68 'Very wide image',
69 ),
70
71 array(
72 array( 100, 1000 ),
73 array(
74 'width' => 1, 'height' => 10,
75 'physicalWidth' => 1, 'physicalHeight' => 10,
76 'page' => 1,
77 ),
78 array( 'width' => 1 ),
79 'Very high image',
80 ),
81 array(
82 array( 100, 1000 ),
83 array(
84 'width' => 1, 'height' => 5,
85 'physicalWidth' => 1, 'physicalHeight' => 10,
86 'page' => 1,
87 ),
88 array( 'width' => 10, 'height' => 5 ),
89 'Very high image with height set',
90 ),
91 /* Max image area */
92 array(
93 array( 4000, 4000 ),
94 array(
95 'width' => 5000, 'height' => 5000,
96 'physicalWidth' => 4000, 'physicalHeight' => 4000,
97 'page' => 1,
98 ),
99 array( 'width' => 5000 ),
100 'Bigger than max image size but doesn\'t need scaling',
101 ),
102 );
103 }
104 function testTooBigImage() {
105 $file = new FakeDimensionFile( array( 4000, 4000 ) );
106 $handler = new BitmapHandler;
107 $params = array( 'width' => '3700' ); // Still bigger than max size.
108 $this->assertFalse( $handler->normaliseParams( $file, $params ) );
109 }
110 function testTooBigMustRenderImage() {
111 $file = new FakeDimensionFile( array( 4000, 4000 ) );
112 $file->mustRender = true;
113 $handler = new BitmapHandler;
114 $params = array( 'width' => '5000' ); // Still bigger than max size.
115 $this->assertFalse( $handler->normaliseParams( $file, $params ) );
116 }
117 }
118
119 class FakeDimensionFile extends File {
120 public $mustRender = false;
121
122 public function __construct( $dimensions ) {
123 parent::__construct( Title::makeTitle( NS_FILE, 'Test' ), null );
124
125 $this->dimensions = $dimensions;
126 }
127 public function getWidth( $page = 1 ) {
128 return $this->dimensions[0];
129 }
130 public function getHeight( $page = 1 ) {
131 return $this->dimensions[1];
132 }
133 public function mustRender() {
134 return $this->mustRender;
135 }
136 }