MediaWiki  1.30.0
ExifRotationTest.php
Go to the documentation of this file.
1 <?php
11 
12  protected function setUp() {
13  parent::setUp();
14  $this->checkPHPExtension( 'exif' );
15 
16  $this->handler = new BitmapHandler();
17 
18  $this->setMwGlobals( [
19  'wgShowEXIF' => true,
20  'wgEnableAutoRotation' => true,
21  ] );
22  }
23 
27  protected function createsThumbnails() {
28  return true;
29  }
30 
34  public function testMetadata( $name, $type, $info ) {
35  if ( !$this->handler->canRotate() ) {
36  $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
37  }
38  $file = $this->dataFile( $name, $type );
39  $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
40  $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
41  }
42 
50  public function testMetadataAutoRotate( $name, $type, $info ) {
51  $this->setMwGlobals( 'wgEnableAutoRotation', null );
52  $this->setMwGlobals( 'wgUseImageMagick', true );
53  $this->setMwGlobals( 'wgUseImageResize', true );
54 
55  $file = $this->dataFile( $name, $type );
56  $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
57  $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
58  }
59 
64  public function testRotationRendering( $name, $type, $info, $thumbs ) {
65  if ( !$this->handler->canRotate() ) {
66  $this->markTestSkipped( "This test needs a rasterizer that can auto-rotate." );
67  }
68  foreach ( $thumbs as $size => $out ) {
69  if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
70  $params = [
71  'width' => $matches[1],
72  ];
73  } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
74  $params = [
75  'width' => $matches[1],
76  'height' => $matches[2]
77  ];
78  } else {
79  throw new MWException( 'bogus test data format ' . $size );
80  }
81 
82  $file = $this->dataFile( $name, $type );
83  $thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
84 
85  $this->assertEquals(
86  $out[0],
87  $thumb->getWidth(),
88  "$name: thumb reported width check for $size"
89  );
90  $this->assertEquals(
91  $out[1],
92  $thumb->getHeight(),
93  "$name: thumb reported height check for $size"
94  );
95 
96  $gis = getimagesize( $thumb->getLocalCopyPath() );
97  if ( $out[0] > $info['width'] ) {
98  // Physical image won't be scaled bigger than the original.
99  $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
100  $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
101  } else {
102  $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
103  $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
104  }
105  }
106  }
107 
108  public static function provideFiles() {
109  return [
110  [
111  'landscape-plain.jpg',
112  'image/jpeg',
113  [
114  'width' => 1024,
115  'height' => 768,
116  ],
117  [
118  '800x600px' => [ 800, 600 ],
119  '9999x800px' => [ 1067, 800 ],
120  '800px' => [ 800, 600 ],
121  '600px' => [ 600, 450 ],
122  ]
123  ],
124  [
125  'portrait-rotated.jpg',
126  'image/jpeg',
127  [
128  'width' => 768, // as rotated
129  'height' => 1024, // as rotated
130  ],
131  [
132  '800x600px' => [ 450, 600 ],
133  '9999x800px' => [ 600, 800 ],
134  '800px' => [ 800, 1067 ],
135  '600px' => [ 600, 800 ],
136  ]
137  ]
138  ];
139  }
140 
145  public function testMetadataNoAutoRotate( $name, $type, $info ) {
146  $this->setMwGlobals( 'wgEnableAutoRotation', false );
147 
148  $file = $this->dataFile( $name, $type );
149  $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
150  $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
151  }
152 
157  public function testMetadataAutoRotateUnsupported( $name, $type, $info ) {
158  $this->setMwGlobals( 'wgEnableAutoRotation', null );
159  $this->setMwGlobals( 'wgUseImageResize', false );
160 
161  $file = $this->dataFile( $name, $type );
162  $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" );
163  $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" );
164  }
165 
170  public function testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs ) {
171  $this->setMwGlobals( 'wgEnableAutoRotation', false );
172 
173  foreach ( $thumbs as $size => $out ) {
174  if ( preg_match( '/^(\d+)px$/', $size, $matches ) ) {
175  $params = [
176  'width' => $matches[1],
177  ];
178  } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) {
179  $params = [
180  'width' => $matches[1],
181  'height' => $matches[2]
182  ];
183  } else {
184  throw new MWException( 'bogus test data format ' . $size );
185  }
186 
187  $file = $this->dataFile( $name, $type );
188  $thumb = $file->transform( $params, File::RENDER_NOW | File::RENDER_FORCE );
189 
190  $this->assertEquals(
191  $out[0],
192  $thumb->getWidth(),
193  "$name: thumb reported width check for $size"
194  );
195  $this->assertEquals(
196  $out[1],
197  $thumb->getHeight(),
198  "$name: thumb reported height check for $size"
199  );
200 
201  $gis = getimagesize( $thumb->getLocalCopyPath() );
202  if ( $out[0] > $info['width'] ) {
203  // Physical image won't be scaled bigger than the original.
204  $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size" );
205  $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size" );
206  } else {
207  $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size" );
208  $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size" );
209  }
210  }
211  }
212 
213  public static function provideFilesNoAutoRotate() {
214  return [
215  [
216  'landscape-plain.jpg',
217  'image/jpeg',
218  [
219  'width' => 1024,
220  'height' => 768,
221  ],
222  [
223  '800x600px' => [ 800, 600 ],
224  '9999x800px' => [ 1067, 800 ],
225  '800px' => [ 800, 600 ],
226  '600px' => [ 600, 450 ],
227  ]
228  ],
229  [
230  'portrait-rotated.jpg',
231  'image/jpeg',
232  [
233  'width' => 1024, // since not rotated
234  'height' => 768, // since not rotated
235  ],
236  [
237  '800x600px' => [ 800, 600 ],
238  '9999x800px' => [ 1067, 800 ],
239  '800px' => [ 800, 600 ],
240  '600px' => [ 600, 450 ],
241  ]
242  ]
243  ];
244  }
245 
246  const TEST_WIDTH = 100;
247  const TEST_HEIGHT = 200;
248 
252  public function testBitmapExtractPreRotationDimensions( $rotation, $expected ) {
253  $result = $this->handler->extractPreRotationDimensions( [
254  'physicalWidth' => self::TEST_WIDTH,
255  'physicalHeight' => self::TEST_HEIGHT,
256  ], $rotation );
257  $this->assertEquals( $expected, $result );
258  }
259 
260  public static function provideBitmapExtractPreRotationDimensions() {
261  return [
262  [
263  0,
265  ],
266  [
267  90,
269  ],
270  [
271  180,
273  ],
274  [
275  270,
277  ],
278  ];
279  }
280 }
ExifRotationTest\provideFilesNoAutoRotate
static provideFilesNoAutoRotate()
Definition: ExifRotationTest.php:213
ExifRotationTest\createsThumbnails
createsThumbnails()
Mark this test as creating thumbnail files.
Definition: ExifRotationTest.php:27
ExifRotationTest\testMetadataNoAutoRotate
testMetadataNoAutoRotate( $name, $type, $info)
Same as before, but with auto-rotation disabled.
Definition: ExifRotationTest.php:145
ExifRotationTest\TEST_WIDTH
const TEST_WIDTH
Definition: ExifRotationTest.php:246
ExifRotationTest\testMetadataAutoRotateUnsupported
testMetadataAutoRotateUnsupported( $name, $type, $info)
Same as before, but with auto-rotation set to auto and an image scaler that doesn't support it.
Definition: ExifRotationTest.php:157
$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. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. '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 '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 '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 '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. '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 IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() '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 Sanitizer::validateEmail(), 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. '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) '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 '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:Array with elements of the form "language:title" in the order that they will be output. & $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. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. 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:1963
File\RENDER_FORCE
const RENDER_FORCE
Force rendering even if thumbnail already exist and using RENDER_NOW I.e.
Definition: File.php:64
$params
$params
Definition: styleTest.css.php:40
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
ExifRotationTest\testMetadataAutoRotate
testMetadataAutoRotate( $name, $type, $info)
Same as before, but with auto-rotation set to auto.
Definition: ExifRotationTest.php:50
ExifRotationTest\testBitmapExtractPreRotationDimensions
testBitmapExtractPreRotationDimensions( $rotation, $expected)
provideBitmapExtractPreRotationDimensions
Definition: ExifRotationTest.php:252
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ExifRotationTest\testMetadata
testMetadata( $name, $type, $info)
provideFiles
Definition: ExifRotationTest.php:34
MediaWikiMediaTestCase
Specificly for testing Media handlers.
Definition: MediaWikiMediaTestCase.php:5
handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves set to a MediaTransformOutput the error message to be returned in an array you should do so by altering $wgNamespaceProtection and $wgNamespaceContentModels outside the handler
Definition: hooks.txt:781
MWException
MediaWiki exception.
Definition: MWException.php:26
BitmapHandler
Generic handler for bitmap images.
Definition: Bitmap.php:29
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
$matches
$matches
Definition: NoLocalSettings.php:24
MediaWikiMediaTestCase\dataFile
dataFile( $name, $type=null)
Utility function: Get a new file object for a file on disk but not actually in db.
Definition: MediaWikiMediaTestCase.php:76
ExifRotationTest\testRotationRendering
testRotationRendering( $name, $type, $info, $thumbs)
provideFiles
Definition: ExifRotationTest.php:64
ExifRotationTest\provideFiles
static provideFiles()
Definition: ExifRotationTest.php:108
ExifRotationTest\testRotationRenderingNoAutoRotate
testRotationRenderingNoAutoRotate( $name, $type, $info, $thumbs)
provideFilesNoAutoRotate
Definition: ExifRotationTest.php:170
ExifRotationTest\setUp
setUp()
Definition: ExifRotationTest.php:12
ExifRotationTest
Tests related to auto rotation.
Definition: ExifRotationTest.php:10
ExifRotationTest\TEST_HEIGHT
const TEST_HEIGHT
Definition: ExifRotationTest.php:247
File\RENDER_NOW
const RENDER_NOW
Force rendering in the current process.
Definition: File.php:59
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:1770
ExifRotationTest\provideBitmapExtractPreRotationDimensions
static provideBitmapExtractPreRotationDimensions()
Definition: ExifRotationTest.php:260
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:781
$type
$type
Definition: testCompression.php:48