test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / media / BitmapScalingTest.php
blobc4706bf64449def39051281b5a7f2db2189eca53
1 <?php
3 class BitmapScalingTest extends MediaWikiTestCase {
5 protected function setUp() {
6 parent::setUp();
8 $this->setMwGlobals( array(
9 'wgMaxImageArea' => 1.25e7, // 3500x3500
10 'wgCustomConvertCommand' => 'dummy', // Set so that we don't get client side rendering
11 ) );
14 /**
15 * @dataProvider provideNormaliseParams
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 );
25 public static 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,
35 array( 'width' => 512 ),
36 'Resizing with width set',
38 array(
39 array( 1024, 768 ),
40 array(
41 'width' => 512, 'height' => 384,
42 'physicalWidth' => 512, 'physicalHeight' => 384,
43 'page' => 1,
45 array( 'width' => 512, 'height' => 768 ),
46 'Resizing with height set too high',
48 array(
49 array( 1024, 768 ),
50 array(
51 'width' => 512, 'height' => 384,
52 'physicalWidth' => 512, 'physicalHeight' => 384,
53 'page' => 1,
55 array( 'width' => 1024, 'height' => 384 ),
56 'Resizing with height set',
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,
67 array( 'width' => 5 ),
68 'Very wide image',
71 array(
72 array( 100, 1000 ),
73 array(
74 'width' => 1, 'height' => 10,
75 'physicalWidth' => 1, 'physicalHeight' => 10,
76 'page' => 1,
78 array( 'width' => 1 ),
79 'Very high image',
81 array(
82 array( 100, 1000 ),
83 array(
84 'width' => 1, 'height' => 5,
85 'physicalWidth' => 1, 'physicalHeight' => 10,
86 'page' => 1,
88 array( 'width' => 10, 'height' => 5 ),
89 'Very high image with height set',
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,
99 array( 'width' => 5000 ),
100 'Bigger than max image size but doesn\'t need scaling',
105 function testTooBigImage() {
106 $file = new FakeDimensionFile( array( 4000, 4000 ) );
107 $handler = new BitmapHandler;
108 $params = array( 'width' => '3700' ); // Still bigger than max size.
109 $this->assertEquals( 'TransformParameterError',
110 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
113 function testTooBigMustRenderImage() {
114 $file = new FakeDimensionFile( array( 4000, 4000 ) );
115 $file->mustRender = true;
116 $handler = new BitmapHandler;
117 $params = array( 'width' => '5000' ); // Still bigger than max size.
118 $this->assertEquals( 'TransformParameterError',
119 get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
122 function testImageArea() {
123 $file = new FakeDimensionFile( array( 7, 9 ) );
124 $handler = new BitmapHandler;
125 $this->assertEquals( 63, $handler->getImageArea( $file ) );
129 class FakeDimensionFile extends File {
130 public $mustRender = false;
132 public function __construct( $dimensions ) {
133 parent::__construct( Title::makeTitle( NS_FILE, 'Test' ),
134 new NullRepo( null ) );
136 $this->dimensions = $dimensions;
139 public function getWidth( $page = 1 ) {
140 return $this->dimensions[0];
143 public function getHeight( $page = 1 ) {
144 return $this->dimensions[1];
147 public function mustRender() {
148 return $this->mustRender;
151 public function getPath() {
152 return '';