wiki.techinc.nl/tests/phpunit/includes/page/ImagePage404Test.php
Tim Starling 5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00

61 lines
1.5 KiB
PHP

<?php
use MediaWiki\MainConfigNames;
use MediaWiki\Title\Title;
/**
* For doing Image Page tests that rely on 404 thumb handling
*/
class ImagePage404Test extends MediaWikiMediaTestCase {
protected function getRepoOptions() {
return parent::getRepoOptions() + [ 'transformVia404' => true ];
}
protected function setUp(): void {
$this->overrideConfigValue(
MainConfigNames::ImageLimits,
[
[ 320, 240 ],
[ 640, 480 ],
[ 800, 600 ],
[ 1024, 768 ],
[ 1280, 1024 ]
]
);
parent::setUp();
}
private function getImagePage( $filename ) {
$title = Title::makeTitleSafe( NS_FILE, $filename );
$file = $this->dataFile( $filename );
$iPage = new ImagePage( $title );
$iPage->setFile( $file );
return $iPage;
}
/**
* @covers ImagePage::getThumbSizes
* @dataProvider providerGetThumbSizes
* @param string $filename
* @param int $expectedNumberThumbs How many thumbnails to show
*/
public function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
$iPage = $this->getImagePage( $filename );
$reflection = new ReflectionClass( $iPage );
$reflMethod = $reflection->getMethod( 'getThumbSizes' );
$reflMethod->setAccessible( true );
$actual = $reflMethod->invoke( $iPage, 545, 700 );
$this->assertCount( $expectedNumberThumbs, $actual );
}
public static function providerGetThumbSizes() {
return [
[ 'animated.gif', 6 ],
[ 'Toll_Texas_1.svg', 6 ],
[ '80x60-Greyscale.xcf', 6 ],
[ 'jpeg-comment-binary.jpg', 6 ],
];
}
}