MediaWiki  1.23.8
ExifRotationTest.php
Go to the documentation of this file.
1 <?php
10 
11  protected function setUp() {
12  parent::setUp();
13  $this->checkPHPExtension( 'exif' );
14 
15  $this->handler = new BitmapHandler();
16  $filePath = __DIR__ . '/../../data/media';
17 
18  $tmpDir = $this->getNewTempDirectory();
19 
20  $this->repo = new FSRepo( array(
21  'name' => 'temp',
22  'url' => 'http://localhost/thumbtest',
23  'backend' => new FSFileBackend( array(
24  'name' => 'localtesting',
25  'wikiId' => wfWikiId(),
26  'containerPaths' => array( 'temp-thumb' => $tmpDir, 'data' => $filePath )
27  ) )
28  ) );
29 
30  $this->setMwGlobals( array(
31  'wgShowEXIF' => true,
32  'wgEnableAutoRotation' => true,
33  ) );
34  }
35 
39  public function testMetadata( $name, $type, $info ) {
40  if ( !BitmapHandler::canRotate() ) {
41  $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
42  }
43  $file = $this->dataFile( $name, $type );
44  $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
45  $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
46  }
47 
52  public function testRotationRendering( $name, $type, $info, $thumbs ) {
53  if ( !BitmapHandler::canRotate() ) {
54  $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
55  }
56  foreach ( $thumbs as $size => $out ) {
57  if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
58  $params = array(
59  'width' => $matches[1],
60  );
61  } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
62  $params = array(
63  'width' => $matches[1],
64  'height' => $matches[2]
65  );
66  } else {
67  throw new MWException( 'bogus test data format ' . $size );
68  }
69 
70  $file = $this->dataFile( $name, $type );
71  $thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
72 
73  $this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" );
74  $this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
75 
76  $gis = getimagesize( $thumb->getLocalCopyPath() );
77  if ( $out[0] > $info['width'] ) {
78  // Physical image won't be scaled bigger than the original.
79  $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
80  $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
81  } else {
82  $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
83  $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
84  }
85  }
86  }
87 
88  /* Utility function */
89  private function dataFile( $name, $type ) {
90  return new UnregisteredLocalFile( false, $this->repo,
91  "mwstore://localtesting/data/$name", $type );
92  }
93 
94  public static function provideFiles() {
95  return array(
96  array(
97  'landscape-plain.jpg',
98  'image/jpeg',
99  array(
100  'width' => 1024,
101  'height' => 768,
102  ),
103  array(
104  '800x600px' => array( 800, 600 ),
105  '9999x800px' => array( 1067, 800 ),
106  '800px' => array( 800, 600 ),
107  '600px' => array( 600, 450 ),
108  )
109  ),
110  array(
111  'portrait-rotated.jpg',
112  'image/jpeg',
113  array(
114  'width' => 768, // as rotated
115  'height' => 1024, // as rotated
116  ),
117  array(
118  '800x600px' => array( 450, 600 ),
119  '9999x800px' => array( 600, 800 ),
120  '800px' => array( 800, 1067 ),
121  '600px' => array( 600, 800 ),
122  )
123  )
124  );
125  }
126 
131  public function testMetadataNoAutoRotate( $name, $type, $info ) {
132  $this->setMwGlobals( 'wgEnableAutoRotation', false );
133 
134  $file = $this->dataFile( $name, $type );
135  $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
136  $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
137  }
138 
143  public function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
144  $this->setMwGlobals( 'wgEnableAutoRotation', false );
145 
146  foreach ( $thumbs as $size => $out ) {
147  if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
148  $params = array(
149  'width' => $matches[1],
150  );
151  } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
152  $params = array(
153  'width' => $matches[1],
154  'height' => $matches[2]
155  );
156  } else {
157  throw new MWException( 'bogus test data format ' . $size );
158  }
159 
160  $file = $this->dataFile( $name, $type );
161  $thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
162 
163  $this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" );
164  $this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" );
165 
166  $gis = getimagesize( $thumb->getLocalCopyPath() );
167  if ( $out[0] > $info['width'] ) {
168  // Physical image won't be scaled bigger than the original.
169  $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
170  $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
171  } else {
172  $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
173  $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
174  }
175  }
176  }
177 
178  public static function provideFilesNoAutoRotate() {
179  return array(
180  array(
181  'landscape-plain.jpg',
182  'image/jpeg',
183  array(
184  'width' => 1024,
185  'height' => 768,
186  ),
187  array(
188  '800x600px' => array( 800, 600 ),
189  '9999x800px' => array( 1067, 800 ),
190  '800px' => array( 800, 600 ),
191  '600px' => array( 600, 450 ),
192  )
193  ),
194  array(
195  'portrait-rotated.jpg',
196  'image/jpeg',
197  array(
198  'width' => 1024, // since not rotated
199  'height' => 768, // since not rotated
200  ),
201  array(
202  '800x600px' => array( 800, 600 ),
203  '9999x800px' => array( 1067, 800 ),
204  '800px' => array( 800, 600 ),
205  '600px' => array( 600, 450 ),
206  )
207  )
208  );
209  }
210 
211  const TEST_WIDTH = 100;
212  const TEST_HEIGHT = 200;
213 
217  public function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
218  $result = $this->handler->extractPreRotationDimensions( array(
219  'physicalWidth' => self::TEST_WIDTH,
220  'physicalHeight' => self::TEST_HEIGHT,
221  ), $rotation );
222  $this->assertEquals( $expected, $result );
223  }
224 
225  public static function provideBitmapExtractPreRotationDimensions() {
226  return array(
227  array(
228  0,
229  array( self::TEST_WIDTH, self::TEST_HEIGHT )
230  ),
231  array(
232  90,
233  array( self::TEST_HEIGHT, self::TEST_WIDTH )
234  ),
235  array(
236  180,
237  array( self::TEST_WIDTH, self::TEST_HEIGHT )
238  ),
239  array(
240  270,
241  array( self::TEST_HEIGHT, self::TEST_WIDTH )
242  ),
243  );
244  }
245 }
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
ExifRotationTest\provideFilesNoAutoRotate
static provideFilesNoAutoRotate()
Definition: ExifRotationTest.php:178
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ExifRotationTest\testMetadataNoAutoRotate
testMetadataNoAutoRotate( $name, $type, $info)
Same as before, but with auto-rotation disabled.
Definition: ExifRotationTest.php:131
ExifRotationTest\TEST_WIDTH
const TEST_WIDTH
Definition: ExifRotationTest.php:211
FSRepo
A repository for files accessible via the local filesystem.
Definition: FSRepo.php:33
BitmapHandler\canRotate
static canRotate()
Returns whether the current scaler supports rotation (im and gd do)
Definition: Bitmap.php:743
UnregisteredLocalFile
A file object referring to either a standalone local file, or a file in a local repository with no da...
Definition: UnregisteredLocalFile.php:36
File\RENDER_FORCE
const RENDER_FORCE
Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
Definition: File.php:63
$params
$params
Definition: styleTest.css.php:40
ExifRotationTest\testBitmapExtractPreRotationDimensions
testBitmapExtractPreRotationDimensions( $rotation, $expected)
@dataProvider provideBitmapExtractPreRotationDimensions
Definition: ExifRotationTest.php:217
ExifRotationTest\testMetadata
testMetadata( $name, $type, $info)
@dataProvider provideFiles
Definition: ExifRotationTest.php:39
MWException
MediaWiki exception.
Definition: MWException.php:26
$out
$out
Definition: UtfNormalGenerate.php:167
BitmapHandler
Generic handler for bitmap images.
Definition: Bitmap.php:29
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
ExifRotationTest\testRotationRendering
testRotationRendering( $name, $type, $info, $thumbs)
@dataProvider provideFiles
Definition: ExifRotationTest.php:52
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ExifRotationTest\provideFiles
static provideFiles()
Definition: ExifRotationTest.php:94
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$matches
if(!defined( 'MEDIAWIKI')) if(!isset( $wgVersion)) $matches
Definition: NoLocalSettings.php:33
$size
$size
Definition: RandomTest.php:75
ExifRotationTest\testRotationRenderingNoAutoRotate
testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs)
@dataProvider provideFilesNoAutoRotate
Definition: ExifRotationTest.php:143
ExifRotationTest\dataFile
dataFile( $name, $type)
Definition: ExifRotationTest.php:89
ExifRotationTest\setUp
setUp()
Definition: ExifRotationTest.php:11
ExifRotationTest
Tests related to auto rotation.
Definition: ExifRotationTest.php:9
ExifRotationTest\TEST_HEIGHT
const TEST_HEIGHT
Definition: ExifRotationTest.php:212
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
File\RENDER_NOW
const RENDER_NOW
Force rendering in the current process.
Definition: File.php:58
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1005
ExifRotationTest\provideBitmapExtractPreRotationDimensions
static provideBitmapExtractPreRotationDimensions()
Definition: ExifRotationTest.php:225
$type
$type
Definition: testCompression.php:46
MediaWikiTestCase\getNewTempDirectory
getNewTempDirectory()
obtains a new temporary directory
Definition: MediaWikiTestCase.php:173