4 * Tests related to auto rotation
6 class ExifRotationTest
extends MediaWikiTestCase
{
10 $this->filePath
= dirname( __FILE__
) . '/../../data/media/';
11 $this->handler
= new BitmapHandler();
12 $this->repo
= new FSRepo(array(
14 'directory' => wfTempDir() . '/exif-test-' . time(),
15 'url' => 'http://localhost/thumbtest'
17 if ( !wfDl( 'exif' ) ) {
18 $this->markTestSkipped( "This test needs the exif extension." );
21 $this->show
= $wgShowEXIF;
24 public function tearDown() {
26 $wgShowEXIF = $this->show
;
31 * @dataProvider providerFiles
33 function testMetadata( $name, $type, $info ) {
34 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. $name, $type );
35 $this->assertEquals( $file->getWidth(), $info['width'], "$name: width check" );
36 $this->assertEquals( $file->getHeight(), $info['height'], "$name: height check" );
41 * @dataProvider providerFiles
43 function testRotationRendering( $name, $type, $info ) {
44 $file = $this->localFile( $name, $type );
45 $thumb = $file->transform( array(
48 ), File
::RENDER_NOW
);
50 $this->assertEquals( $thumb->getWidth(), $info['thumbWidth'], "$name: thumb reported width check" );
51 $this->assertEquals( $thumb->getHeight(), $info['thumbHeight'], "$name: thumb reported height check" );
53 $gis = getimagesize( $thumb->getPath() );
54 $this->assertEquals( $gis[0], $info['thumbWidth'], "$name: thumb actual width check");
55 $this->assertEquals( $gis[0], $info['thumbWidth'], "$name: thumb actual height check");
58 private function localFile( $name, $type ) {
59 return new UnregisteredLocalFile( false, $this->repo
, $this->filePath
. $name, $type );
62 function providerFiles() {
65 'landscape-plain.jpg',
75 'portrait-rotated.jpg',
78 'width' => 768, // as rotated
79 'height' => 1024, // as rotated
88 const TEST_WIDTH
= 100;
89 const TEST_HEIGHT
= 200;
92 * @dataProvider provideBitmapExtractPreRotationDimensions
94 function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
95 $result = $this->handler
->extractPreRotationDimensions( array(
96 'physicalWidth' => self
::TEST_WIDTH
,
97 'physicalHeight' => self
::TEST_HEIGHT
,
99 $this->assertEquals( $expected, $result );
102 function provideBitmapExtractPreRotationDimensions() {
106 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
110 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)
114 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
118 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)
123 function testWidthFlipping() {
124 # Any further test require a scaler that can rotate
125 if ( !BitmapHandler
::canRotate() ) {
126 $this->markTestSkipped( 'Scaler does not support rotation' );
129 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. 'portrait-rotated.jpg', 'image/jpeg' );
130 $params = array( 'width' => '50' );
131 $this->assertTrue( $this->handler
->normaliseParams( $file, $params ) );
133 $this->assertEquals( 50, $params['height'] );
134 $this->assertEquals( round( (768/1024)*50 ), $params['width'], '', 0.1 );
136 function testWidthNotFlipping() {
137 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. 'landscape-plain.jpg', 'image/jpeg' );
138 $params = array( 'width' => '50' );
139 $this->assertTrue( $this->handler
->normaliseParams( $file, $params ) );
141 $this->assertEquals( 50, $params['width'] );
142 $this->assertEquals( round( (768/1024)*50 ), $params['height'], '', 0.1 );