3 * Tests related to auto rotation.
9 class ExifRotationTest
extends MediaWikiMediaTestCase
{
11 protected function setUp() {
13 $this->checkPHPExtension( 'exif' );
15 $this->handler
= new BitmapHandler();
17 $this->setMwGlobals( array(
19 'wgEnableAutoRotation' => true,
24 * Mark this test as creating thumbnail files.
26 protected function createsThumbnails() {
31 * @dataProvider provideFiles
33 public function testMetadata( $name, $type, $info ) {
34 if ( !BitmapHandler
::canRotate() ) {
35 $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
37 $file = $this->dataFile( $name, $type );
38 $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
39 $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
44 * @dataProvider provideFiles
46 public function testRotationRendering( $name, $type, $info, $thumbs ) {
47 if ( !BitmapHandler
::canRotate() ) {
48 $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
50 foreach ( $thumbs as $size => $out ) {
51 if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
53 'width' => $matches[1],
55 } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
57 'width' => $matches[1],
58 'height' => $matches[2]
61 throw new MWException( 'bogus test data format ' . $size );
64 $file = $this->dataFile( $name, $type );
65 $thumb = $file->transform( $params, File
::RENDER_NOW | File
::RENDER_FORCE
);
70 "$name: thumb reported width check for $size"
75 "$name: thumb reported height check for $size"
78 $gis = getimagesize( $thumb->getLocalCopyPath() );
79 if ( $out[0] > $info['width'] ) {
80 // Physical image won't be scaled bigger than the original.
81 $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
82 $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
84 $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
85 $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
90 public static function provideFiles() {
93 'landscape-plain.jpg',
100 '800x600px' => array( 800, 600 ),
101 '9999x800px' => array( 1067, 800 ),
102 '800px' => array( 800, 600 ),
103 '600px' => array( 600, 450 ),
107 'portrait-rotated.jpg',
110 'width' => 768, // as rotated
111 'height' => 1024, // as rotated
114 '800x600px' => array( 450, 600 ),
115 '9999x800px' => array( 600, 800 ),
116 '800px' => array( 800, 1067 ),
117 '600px' => array( 600, 800 ),
124 * Same as before, but with auto-rotation disabled.
125 * @dataProvider provideFilesNoAutoRotate
127 public function testMetadataNoAutoRotate( $name, $type, $info ) {
128 $this->setMwGlobals( 'wgEnableAutoRotation', false );
130 $file = $this->dataFile( $name, $type );
131 $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
132 $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
137 * @dataProvider provideFilesNoAutoRotate
139 public function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
140 $this->setMwGlobals( 'wgEnableAutoRotation', false );
142 foreach ( $thumbs as $size => $out ) {
143 if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
145 'width' => $matches[1],
147 } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
149 'width' => $matches[1],
150 'height' => $matches[2]
153 throw new MWException( 'bogus test data format ' . $size );
156 $file = $this->dataFile( $name, $type );
157 $thumb = $file->transform( $params, File
::RENDER_NOW | File
::RENDER_FORCE
);
162 "$name: thumb reported width check for $size"
167 "$name: thumb reported height check for $size"
170 $gis = getimagesize( $thumb->getLocalCopyPath() );
171 if ( $out[0] > $info['width'] ) {
172 // Physical image won't be scaled bigger than the original.
173 $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
174 $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
176 $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
177 $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
182 public static function provideFilesNoAutoRotate() {
185 'landscape-plain.jpg',
192 '800x600px' => array( 800, 600 ),
193 '9999x800px' => array( 1067, 800 ),
194 '800px' => array( 800, 600 ),
195 '600px' => array( 600, 450 ),
199 'portrait-rotated.jpg',
202 'width' => 1024, // since not rotated
203 'height' => 768, // since not rotated
206 '800x600px' => array( 800, 600 ),
207 '9999x800px' => array( 1067, 800 ),
208 '800px' => array( 800, 600 ),
209 '600px' => array( 600, 450 ),
215 const TEST_WIDTH
= 100;
216 const TEST_HEIGHT
= 200;
219 * @dataProvider provideBitmapExtractPreRotationDimensions
221 public function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
222 $result = $this->handler
->extractPreRotationDimensions( array(
223 'physicalWidth' => self
::TEST_WIDTH
,
224 'physicalHeight' => self
::TEST_HEIGHT
,
226 $this->assertEquals( $expected, $result );
229 public static function provideBitmapExtractPreRotationDimensions() {
233 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
237 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)
241 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
245 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)