2011-06-13 22:13:38 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-12-03 08:14:32 +00:00
|
|
|
* Tests related to auto rotation.
|
|
|
|
|
*
|
|
|
|
|
* @group medium
|
2013-10-23 22:12:39 +00:00
|
|
|
*
|
|
|
|
|
* @todo covers tags
|
2011-06-13 22:13:38 +00:00
|
|
|
*/
|
|
|
|
|
class ExifRotationTest extends MediaWikiTestCase {
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2011-07-15 15:13:18 +00:00
|
|
|
parent::setUp();
|
2013-10-09 16:46:57 +00:00
|
|
|
if ( !extension_loaded( 'exif' ) ) {
|
|
|
|
|
$this->markTestSkipped( "This test needs the exif extension." );
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-09 20:13:09 +00:00
|
|
|
$this->handler = new BitmapHandler();
|
2012-08-27 19:03:15 +00:00
|
|
|
$filePath = __DIR__ . '/../../data/media';
|
2012-02-24 15:43:11 +00:00
|
|
|
|
2012-04-10 14:57:15 +00:00
|
|
|
$tmpDir = $this->getNewTempDirectory();
|
2012-02-24 15:43:11 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->repo = new FSRepo( array(
|
2013-02-15 10:17:52 +00:00
|
|
|
'name' => 'temp',
|
|
|
|
|
'url' => 'http://localhost/thumbtest',
|
|
|
|
|
'backend' => new FSFileBackend( array(
|
|
|
|
|
'name' => 'localtesting',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
2012-01-07 01:33:23 +00:00
|
|
|
'containerPaths' => array( 'temp-thumb' => $tmpDir, 'data' => $filePath )
|
|
|
|
|
) )
|
2011-12-20 03:52:06 +00:00
|
|
|
) );
|
2011-11-11 04:09:05 +00:00
|
|
|
|
2013-03-21 19:35:44 +00:00
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgShowEXIF' => true,
|
|
|
|
|
'wgEnableAutoRotation' => true,
|
|
|
|
|
) );
|
2011-06-13 22:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideFiles
|
2011-06-13 22:13:38 +00:00
|
|
|
*/
|
2013-10-23 22:12:39 +00:00
|
|
|
public function testMetadata( $name, $type, $info ) {
|
2011-11-11 04:09:05 +00:00
|
|
|
if ( !BitmapHandler::canRotate() ) {
|
|
|
|
|
$this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
$file = $this->dataFile( $name, $type );
|
2011-09-20 20:04:26 +00:00
|
|
|
$this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
|
|
|
|
|
$this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
|
2011-06-13 22:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-20 19:39:17 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideFiles
|
2011-09-20 19:39:17 +00:00
|
|
|
*/
|
2013-10-23 22:12:39 +00:00
|
|
|
public function testRotationRendering( $name, $type, $info, $thumbs ) {
|
2011-11-11 04:09:05 +00:00
|
|
|
if ( !BitmapHandler::canRotate() ) {
|
|
|
|
|
$this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
|
|
|
|
|
}
|
2013-02-15 10:17:52 +00:00
|
|
|
foreach ( $thumbs as $size => $out ) {
|
|
|
|
|
if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
|
2011-09-20 20:04:26 +00:00
|
|
|
$params = array(
|
|
|
|
|
'width' => $matches[1],
|
|
|
|
|
);
|
|
|
|
|
} elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
|
|
|
|
|
$params = array(
|
|
|
|
|
'width' => $matches[1],
|
|
|
|
|
'height' => $matches[2]
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2013-02-15 10:17:52 +00:00
|
|
|
throw new MWException( 'bogus test data format ' . $size );
|
2011-09-20 20:04:26 +00:00
|
|
|
}
|
2011-09-20 19:39:17 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$file = $this->dataFile( $name, $type );
|
|
|
|
|
$thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
|
2011-09-20 19:39:17 +00:00
|
|
|
|
2011-09-20 20:04:26 +00:00
|
|
|
$this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" );
|
|
|
|
|
$this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$gis = getimagesize( $thumb->getLocalCopyPath() );
|
2013-02-15 10:17:52 +00:00
|
|
|
if ( $out[0] > $info['width'] ) {
|
2011-09-20 20:04:26 +00:00
|
|
|
// Physical image won't be scaled bigger than the original.
|
2013-02-15 10:17:52 +00:00
|
|
|
$this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
|
|
|
|
|
$this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
|
2011-09-20 20:04:26 +00:00
|
|
|
} else {
|
2013-02-15 10:17:52 +00:00
|
|
|
$this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
|
|
|
|
|
$this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
|
2011-09-20 20:04:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-09-20 19:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
/* Utility function */
|
2011-12-20 03:52:06 +00:00
|
|
|
private function dataFile( $name, $type ) {
|
|
|
|
|
return new UnregisteredLocalFile( false, $this->repo,
|
|
|
|
|
"mwstore://localtesting/data/$name", $type );
|
2011-09-20 19:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideFiles() {
|
2011-06-13 22:13:38 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
'landscape-plain.jpg',
|
|
|
|
|
'image/jpeg',
|
|
|
|
|
array(
|
|
|
|
|
'width' => 1024,
|
|
|
|
|
'height' => 768,
|
2011-09-20 20:04:26 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'800x600px' => array( 800, 600 ),
|
|
|
|
|
'9999x800px' => array( 1067, 800 ),
|
|
|
|
|
'800px' => array( 800, 600 ),
|
|
|
|
|
'600px' => array( 600, 450 ),
|
2011-06-13 22:13:38 +00:00
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'portrait-rotated.jpg',
|
|
|
|
|
'image/jpeg',
|
|
|
|
|
array(
|
|
|
|
|
'width' => 768, // as rotated
|
|
|
|
|
'height' => 1024, // as rotated
|
2011-09-20 20:04:26 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'800x600px' => array( 450, 600 ),
|
|
|
|
|
'9999x800px' => array( 600, 800 ),
|
|
|
|
|
'800px' => array( 800, 1067 ),
|
|
|
|
|
'600px' => array( 600, 800 ),
|
2011-06-13 22:13:38 +00:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-11-11 04:09:05 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Same as before, but with auto-rotation disabled.
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideFilesNoAutoRotate
|
2011-11-11 04:09:05 +00:00
|
|
|
*/
|
2013-10-23 22:12:39 +00:00
|
|
|
public function testMetadataNoAutoRotate( $name, $type, $info ) {
|
2013-03-21 19:35:44 +00:00
|
|
|
$this->setMwGlobals( 'wgEnableAutoRotation', false );
|
2011-11-11 04:09:05 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$file = $this->dataFile( $name, $type );
|
2011-11-11 04:09:05 +00:00
|
|
|
$this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
|
|
|
|
|
$this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
2012-10-08 10:56:20 +00:00
|
|
|
* @dataProvider provideFilesNoAutoRotate
|
2011-11-11 04:09:05 +00:00
|
|
|
*/
|
2013-10-23 22:12:39 +00:00
|
|
|
public function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
|
2013-03-21 19:35:44 +00:00
|
|
|
$this->setMwGlobals( 'wgEnableAutoRotation', false );
|
2011-11-11 04:09:05 +00:00
|
|
|
|
2013-02-15 10:17:52 +00:00
|
|
|
foreach ( $thumbs as $size => $out ) {
|
|
|
|
|
if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
|
2011-11-11 04:09:05 +00:00
|
|
|
$params = array(
|
|
|
|
|
'width' => $matches[1],
|
|
|
|
|
);
|
|
|
|
|
} elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
|
|
|
|
|
$params = array(
|
|
|
|
|
'width' => $matches[1],
|
|
|
|
|
'height' => $matches[2]
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2013-02-15 10:17:52 +00:00
|
|
|
throw new MWException( 'bogus test data format ' . $size );
|
2011-11-11 04:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$file = $this->dataFile( $name, $type );
|
|
|
|
|
$thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
|
2011-11-11 04:09:05 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" );
|
|
|
|
|
$this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$gis = getimagesize( $thumb->getLocalCopyPath() );
|
2013-02-15 10:17:52 +00:00
|
|
|
if ( $out[0] > $info['width'] ) {
|
2011-11-11 04:09:05 +00:00
|
|
|
// Physical image won't be scaled bigger than the original.
|
2013-02-15 10:17:52 +00:00
|
|
|
$this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
|
|
|
|
|
$this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
|
2011-11-11 04:09:05 +00:00
|
|
|
} else {
|
2013-02-15 10:17:52 +00:00
|
|
|
$this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
|
|
|
|
|
$this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
|
2011-11-11 04:09:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideFilesNoAutoRotate() {
|
2011-11-11 04:09:05 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
'landscape-plain.jpg',
|
|
|
|
|
'image/jpeg',
|
|
|
|
|
array(
|
|
|
|
|
'width' => 1024,
|
|
|
|
|
'height' => 768,
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'800x600px' => array( 800, 600 ),
|
|
|
|
|
'9999x800px' => array( 1067, 800 ),
|
|
|
|
|
'800px' => array( 800, 600 ),
|
|
|
|
|
'600px' => array( 600, 450 ),
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'portrait-rotated.jpg',
|
|
|
|
|
'image/jpeg',
|
|
|
|
|
array(
|
|
|
|
|
'width' => 1024, // since not rotated
|
|
|
|
|
'height' => 768, // since not rotated
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'800x600px' => array( 800, 600 ),
|
|
|
|
|
'9999x800px' => array( 1067, 800 ),
|
|
|
|
|
'800px' => array( 800, 600 ),
|
|
|
|
|
'600px' => array( 600, 450 ),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-01-28 10:27:15 +00:00
|
|
|
|
|
|
|
|
|
2011-07-15 15:13:18 +00:00
|
|
|
const TEST_WIDTH = 100;
|
|
|
|
|
const TEST_HEIGHT = 200;
|
2013-01-28 10:27:15 +00:00
|
|
|
|
2011-07-15 15:13:18 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideBitmapExtractPreRotationDimensions
|
|
|
|
|
*/
|
2013-10-23 22:12:39 +00:00
|
|
|
public function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
|
2011-09-09 20:13:09 +00:00
|
|
|
$result = $this->handler->extractPreRotationDimensions( array(
|
2013-02-15 10:17:52 +00:00
|
|
|
'physicalWidth' => self::TEST_WIDTH,
|
|
|
|
|
'physicalHeight' => self::TEST_HEIGHT,
|
|
|
|
|
), $rotation );
|
2011-07-15 15:13:18 +00:00
|
|
|
$this->assertEquals( $expected, $result );
|
|
|
|
|
}
|
2013-01-28 10:27:15 +00:00
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provideBitmapExtractPreRotationDimensions() {
|
2011-07-15 15:13:18 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
0,
|
2013-01-28 10:27:15 +00:00
|
|
|
array( self::TEST_WIDTH, self::TEST_HEIGHT )
|
2011-07-15 15:13:18 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
90,
|
2013-01-28 10:27:15 +00:00
|
|
|
array( self::TEST_HEIGHT, self::TEST_WIDTH )
|
2011-07-15 15:13:18 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
180,
|
2013-01-28 10:27:15 +00:00
|
|
|
array( self::TEST_WIDTH, self::TEST_HEIGHT )
|
2011-07-15 15:13:18 +00:00
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
270,
|
2013-01-28 10:27:15 +00:00
|
|
|
array( self::TEST_HEIGHT, self::TEST_WIDTH )
|
2011-12-20 03:52:06 +00:00
|
|
|
),
|
2011-07-15 15:13:18 +00:00
|
|
|
);
|
|
|
|
|
}
|
2011-06-13 22:13:38 +00:00
|
|
|
}
|