87aed2941fad3006906dd50183bd3cedb88289fc
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( $info['width'], $file->getWidth(), "$name: width check" );
36 $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
41 * @dataProvider providerFiles
43 function testRotationRendering( $name, $type, $info, $thumbs ) {
44 foreach( $thumbs as $size => $out ) {
45 if( preg_match('/^(\d+)px$/', $size, $matches ) ) {
47 'width' => $matches[1],
49 } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
51 'width' => $matches[1],
52 'height' => $matches[2]
55 throw new MWException('bogus test data format ' . $size);
58 $file = $this->localFile( $name, $type );
59 $thumb = $file->transform( $params, File
::RENDER_NOW
);
61 $this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" );
62 $this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
64 $gis = getimagesize( $thumb->getPath() );
65 if ($out[0] > $info['width']) {
66 // Physical image won't be scaled bigger than the original.
67 $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size");
68 $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size");
70 $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size");
71 $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size");
76 private function localFile( $name, $type ) {
77 return new UnregisteredLocalFile( false, $this->repo
, $this->filePath
. $name, $type );
80 function providerFiles() {
83 'landscape-plain.jpg',
90 '800x600px' => array( 800, 600 ),
91 '9999x800px' => array( 1067, 800 ),
92 '800px' => array( 800, 600 ),
93 '600px' => array( 600, 450 ),
97 'portrait-rotated.jpg',
100 'width' => 768, // as rotated
101 'height' => 1024, // as rotated
104 '800x600px' => array( 450, 600 ),
105 '9999x800px' => array( 600, 800 ),
106 '800px' => array( 800, 1067 ),
107 '600px' => array( 600, 800 ),
114 const TEST_WIDTH
= 100;
115 const TEST_HEIGHT
= 200;
118 * @dataProvider provideBitmapExtractPreRotationDimensions
120 function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
121 $result = $this->handler
->extractPreRotationDimensions( array(
122 'physicalWidth' => self
::TEST_WIDTH
,
123 'physicalHeight' => self
::TEST_HEIGHT
,
125 $this->assertEquals( $expected, $result );
128 function provideBitmapExtractPreRotationDimensions() {
132 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
136 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)
140 array( self
::TEST_WIDTH
, self
::TEST_HEIGHT
)
144 array( self
::TEST_HEIGHT
, self
::TEST_WIDTH
)