And allow extensions to add their own media handlers. I'm not too happy with the introduction of another global, but didn't like the alternatives either: * Add some hook to MockMediaHandlerFactory that would allow extensions to add their own stuff in. * Use another hook (like ParserTestTables or ParserTestGlobals) and then override the service with a new instance - seemed too hacky The good thing about this is that it lets us kill off a class. I'm other to other suggestions in case I missed something. Bug: T169258 Depends-On: I5875621c58597426ad5242bf3d07714555c439b5 Change-Id: I1c2e903fb235395a8de8e0f7bf65ce07739d2930
105 lines
2.1 KiB
PHP
105 lines
2.1 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* @group GlobalFunctions
|
|
* @covers ::wfThumbIsStandard
|
|
*/
|
|
class WfThumbIsStandardTest extends MediaWikiTestCase {
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
|
|
$this->setMwGlobals( [
|
|
'wgThumbLimits' => [
|
|
100,
|
|
401
|
|
],
|
|
'wgImageLimits' => [
|
|
[ 300, 225 ],
|
|
[ 800, 600 ],
|
|
],
|
|
] );
|
|
}
|
|
|
|
public static function provideThumbParams() {
|
|
return [
|
|
// Thumb limits
|
|
[
|
|
'Standard thumb width',
|
|
true,
|
|
[ 'width' => 100 ],
|
|
],
|
|
[
|
|
'Standard thumb width',
|
|
true,
|
|
[ 'width' => 401 ],
|
|
],
|
|
// wfThumbIsStandard should match Linker::processResponsiveImages
|
|
// in its rounding behaviour.
|
|
[
|
|
'Standard thumb width (HiDPI 1.5x) - incorrect rounding',
|
|
false,
|
|
[ 'width' => 601 ],
|
|
],
|
|
[
|
|
'Standard thumb width (HiDPI 1.5x)',
|
|
true,
|
|
[ 'width' => 602 ],
|
|
],
|
|
[
|
|
'Standard thumb width (HiDPI 2x)',
|
|
true,
|
|
[ 'width' => 802 ],
|
|
],
|
|
[
|
|
'Non-standard thumb width',
|
|
false,
|
|
[ 'width' => 300 ],
|
|
],
|
|
// Image limits
|
|
// Note: Image limits are measured as pairs. Individual values
|
|
// may be non-standard based on the aspect ratio.
|
|
[
|
|
'Standard image width/height pair',
|
|
true,
|
|
[ 'width' => 250, 'height' => 225 ],
|
|
],
|
|
[
|
|
'Standard image width/height pair',
|
|
true,
|
|
[ 'width' => 667, 'height' => 600 ],
|
|
],
|
|
[
|
|
'Standard image width where image does not fit aspect ratio',
|
|
false,
|
|
[ 'width' => 300 ],
|
|
],
|
|
[
|
|
'Implicit width from image width/height pair aspect ratio fit',
|
|
true,
|
|
// 2000x1800 fit inside 300x225 makes w=250
|
|
[ 'width' => 250 ],
|
|
],
|
|
[
|
|
'Height-only is always non-standard',
|
|
false,
|
|
[ 'height' => 225 ],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideThumbParams
|
|
*/
|
|
public function testIsStandard( $message, $expected, $params ) {
|
|
$handlers = MediaWikiServices::getInstance()->getMainConfig()->get( 'ParserTestMediaHandlers' );
|
|
$this->setService( 'MediaHandlerFactory', new MediaHandlerFactory( $handlers ) );
|
|
$this->assertSame(
|
|
$expected,
|
|
wfThumbIsStandard( new FakeDimensionFile( [ 2000, 1800 ], 'image/jpeg' ), $params ),
|
|
$message
|
|
);
|
|
}
|
|
}
|