2011-06-13 22:13:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2011-07-15 15:13:18 +00:00
|
|
|
* Tests related to auto rotation
|
2011-06-13 22:13:38 +00:00
|
|
|
*/
|
|
|
|
|
class ExifRotationTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
function setUp() {
|
2011-07-15 15:13:18 +00:00
|
|
|
parent::setUp();
|
2011-08-17 23:28:31 +00:00
|
|
|
$this->filePath = dirname( __FILE__ ) . '/../../data/media/';
|
2011-09-09 20:13:09 +00:00
|
|
|
$this->handler = new BitmapHandler();
|
2011-09-20 19:39:17 +00:00
|
|
|
$this->repo = new FSRepo(array(
|
|
|
|
|
'name' => 'temp',
|
|
|
|
|
'directory' => wfTempDir() . '/exif-test-' . time(),
|
|
|
|
|
'url' => 'http://localhost/thumbtest'
|
|
|
|
|
));
|
2011-09-18 01:53:09 +00:00
|
|
|
if ( !wfDl( 'exif' ) ) {
|
|
|
|
|
$this->markTestSkipped( "This test needs the exif extension." );
|
|
|
|
|
}
|
|
|
|
|
global $wgShowEXIF;
|
|
|
|
|
$this->show = $wgShowEXIF;
|
|
|
|
|
$wgShowEXIF = true;
|
|
|
|
|
}
|
|
|
|
|
public function tearDown() {
|
|
|
|
|
global $wgShowEXIF;
|
|
|
|
|
$wgShowEXIF = $this->show;
|
2011-06-13 22:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider providerFiles
|
|
|
|
|
*/
|
|
|
|
|
function testMetadata( $name, $type, $info ) {
|
2011-08-17 23:28:31 +00:00
|
|
|
$file = UnregisteredLocalFile::newFromPath( $this->filePath . $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
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider providerFiles
|
|
|
|
|
*/
|
2011-09-20 20:04:26 +00:00
|
|
|
function testRotationRendering( $name, $type, $info, $thumbs ) {
|
|
|
|
|
foreach( $thumbs as $size => $out ) {
|
|
|
|
|
if( preg_match('/^(\d+)px$/', $size, $matches ) ) {
|
|
|
|
|
$params = array(
|
|
|
|
|
'width' => $matches[1],
|
|
|
|
|
);
|
|
|
|
|
} elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
|
|
|
|
|
$params = array(
|
|
|
|
|
'width' => $matches[1],
|
|
|
|
|
'height' => $matches[2]
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
throw new MWException('bogus test data format ' . $size);
|
|
|
|
|
}
|
2011-09-20 19:39:17 +00:00
|
|
|
|
2011-09-20 20:04:26 +00:00
|
|
|
$file = $this->localFile( $name, $type );
|
|
|
|
|
$thumb = $file->transform( $params, File::RENDER_NOW );
|
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" );
|
|
|
|
|
|
|
|
|
|
$gis = getimagesize( $thumb->getPath() );
|
|
|
|
|
if ($out[0] > $info['width']) {
|
|
|
|
|
// Physical image won't be scaled bigger than the original.
|
|
|
|
|
$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");
|
|
|
|
|
} else {
|
|
|
|
|
$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 19:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function localFile( $name, $type ) {
|
|
|
|
|
return new UnregisteredLocalFile( false, $this->repo, $this->filePath . $name, $type );
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-13 22:13:38 +00:00
|
|
|
function providerFiles() {
|
|
|
|
|
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-07-15 15:13:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const TEST_WIDTH = 100;
|
|
|
|
|
const TEST_HEIGHT = 200;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideBitmapExtractPreRotationDimensions
|
|
|
|
|
*/
|
|
|
|
|
function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
|
2011-09-09 20:13:09 +00:00
|
|
|
$result = $this->handler->extractPreRotationDimensions( array(
|
2011-07-15 15:13:18 +00:00
|
|
|
'physicalWidth' => self::TEST_WIDTH,
|
|
|
|
|
'physicalHeight' => self::TEST_HEIGHT,
|
|
|
|
|
), $rotation );
|
|
|
|
|
$this->assertEquals( $expected, $result );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function provideBitmapExtractPreRotationDimensions() {
|
|
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
0,
|
|
|
|
|
array( self::TEST_WIDTH, self::TEST_HEIGHT )
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
90,
|
|
|
|
|
array( self::TEST_HEIGHT, self::TEST_WIDTH )
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
180,
|
|
|
|
|
array( self::TEST_WIDTH, self::TEST_HEIGHT )
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
270,
|
|
|
|
|
array( self::TEST_HEIGHT, self::TEST_WIDTH )
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-06-13 22:13:38 +00:00
|
|
|
}
|
|
|
|
|
|