3 * Tests related to auto rotation.
10 class ExifRotationTest
extends MediaWikiMediaTestCase
{
12 protected function setUp() {
14 $this->checkPHPExtension( 'exif' );
16 $this->handler
= new BitmapHandler();
18 $this->setMwGlobals( array(
20 'wgEnableAutoRotation' => true,
25 * Mark this test as creating thumbnail files.
27 protected function createsThumbnails() {
32 * @dataProvider provideFiles
34 public function testMetadata( $name, $type, $info ) {
35 if ( !BitmapHandler
::canRotate() ) {
36 $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
38 $file = $this->dataFile( $name, $type );
39 $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
40 $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
45 * @dataProvider provideFiles
47 public function testRotationRendering( $name, $type, $info, $thumbs ) {
48 if ( !BitmapHandler
::canRotate() ) {
49 $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
51 foreach ( $thumbs as $size => $out ) {
52 if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
54 'width' => $matches[1],
56 } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
58 'width' => $matches[1],
59 'height' => $matches[2]
62 throw new MWException( 'bogus test data format ' . $size );
65 $file = $this->dataFile( $name, $type );
66 $thumb = $file->transform( $params, File
::RENDER_NOW | File
::RENDER_FORCE
);
71 "$name: thumb reported width check for $size"
76 "$name: thumb reported height check for $size"
79 $gis = getimagesize( $thumb->getLocalCopyPath() );
80 if ( $out[0] > $info['width'] ) {
81 // Physical image won't be scaled bigger than the original.
82 $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
83 $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
85 $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
86 $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
91 public static function provideFiles() {
94 'landscape-plain.jpg',
101 '800x600px' => array( 800, 600 ),
102 '9999x800px' => array( 1067, 800 ),
103 '800px' => array( 800, 600 ),
104 '600px' => array( 600, 450 ),
108 'portrait-rotated.jpg',
111 'width' => 768, // as rotated
112 'height' => 1024, // as rotated
115 '800x600px' => array( 450, 600 ),
116 '9999x800px' => array( 600, 800 ),
117 '800px' => array( 800, 1067 ),
118 '600px' => array( 600, 800 ),
125 * Same as before, but with auto-rotation disabled.
126 * @dataProvider provideFilesNoAutoRotate
128 public function testMetadataNoAutoRotate( $name, $type, $info ) {
129 $this->setMwGlobals( 'wgEnableAutoRotation', false );
131 $file = $this->dataFile( $name, $type );
132 $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
133 $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
138 * @dataProvider provideFilesNoAutoRotate
140 public function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
141 $this->setMwGlobals( 'wgEnableAutoRotation', false );
143 foreach ( $thumbs as $size => $out ) {
144 if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
146 'width' => $matches[1],
148 } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
150 'width' => $matches[1],
151 'height' => $matches[2]
154 throw new MWException( 'bogus test data format ' . $size );
157 $file = $this->dataFile( $name, $type );
158 $thumb = $file->transform( $params, File
::RENDER_NOW | File
::RENDER_FORCE
);
163 "$name: thumb reported width check for $size"
168 "$name: thumb reported height check for $size"
171 $gis = getimagesize( $thumb->getLocalCopyPath() );
172 if ( $out[0] > $info['width'] ) {
173 // Physical image won't be scaled bigger than the original.
174 $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
175 $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
177 $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
178 $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
183 public static function provideFilesNoAutoRotate() {
186 'landscape-plain.jpg',
193 '800x600px' => array( 800, 600 ),
194 '9999x800px' => array( 1067, 800 ),
195 '800px' => array( 800, 600 ),
196 '600px' => array( 600, 450 ),
200 'portrait-rotated.jpg',
203 'width' => 1024, // since not rotated
204 'height' => 768, // since not rotated
207 '800x600px' => array( 800, 600 ),
208 '9999x800px' => array( 1067, 800 ),
209 '800px' => array( 800, 600 ),
210 '600px' => array( 600, 450 ),
216 const TEST_WIDTH
= 100;
217 const TEST_HEIGHT
= 200;
220 * @dataProvider provideBitmapExtractPreRotationDimensions
222 public function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
223 $result = $this->handler
->extractPreRotationDimensions( array(
224 'physicalWidth' => self
::TEST_WIDTH
,
225 'physicalHeight' => self
::TEST_HEIGHT
,
227 $this->assertEquals( $expected, $result );
230 public static function provideBitmapExtractPreRotationDimensions() {
234 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
238 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)
242 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
246 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)