3 use Wikimedia\TestingAccessWrapper
;
5 class ImagePageTest
extends MediaWikiMediaTestCase
{
7 public function setUp() {
8 $this->setMwGlobals( 'wgImageLimits', [
18 public function getImagePage( $filename ) {
19 $title = Title
::makeTitleSafe( NS_FILE
, $filename );
20 $file = $this->dataFile( $filename );
21 $iPage = new ImagePage( $title );
22 $iPage->setFile( $file );
27 * @covers ImagePage::getDisplayWidthHeight
28 * @dataProvider providerGetDisplayWidthHeight
29 * @param array $dim Array [maxWidth, maxHeight, width, height]
30 * @param array $expected Array [width, height] The width and height we expect to display at
32 public function testGetDisplayWidthHeight( $dim, $expected ) {
33 $iPage = $this->getImagePage( 'animated.gif' );
34 $reflection = new ReflectionClass( $iPage );
35 $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
36 $reflMethod->setAccessible( true );
38 $actual = $reflMethod->invoke( $iPage, $dim[0], $dim[1], $dim[2], $dim[3] );
39 $this->assertEquals( $actual, $expected );
42 public function providerGetDisplayWidthHeight() {
45 [ 1024.0, 768.0, 600.0, 600.0 ],
49 [ 1024.0, 768.0, 1600.0, 600.0 ],
53 [ 1024.0, 768.0, 1024.0, 768.0 ],
57 [ 1024.0, 768.0, 800.0, 1000.0 ],
61 [ 1024.0, 768.0, 0, 1000 ],
65 [ 1024.0, 768.0, 2000, 0 ],
72 * @covers ImagePage::getThumbSizes
73 * @dataProvider providerGetThumbSizes
74 * @param string $filename
75 * @param int $expectedNumberThumbs How many thumbnails to show
77 public function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
78 $iPage = $this->getImagePage( $filename );
79 $reflection = new ReflectionClass( $iPage );
80 $reflMethod = $reflection->getMethod( 'getThumbSizes' );
81 $reflMethod->setAccessible( true );
83 $actual = $reflMethod->invoke( $iPage, 545, 700 );
84 $this->assertEquals( count( $actual ), $expectedNumberThumbs );
87 public function providerGetThumbSizes() {
89 [ 'animated.gif', 2 ],
90 [ 'Toll_Texas_1.svg', 1 ],
91 [ '80x60-Greyscale.xcf', 1 ],
92 [ 'jpeg-comment-binary.jpg', 2 ],
97 * @covers ImagePage::getLanguageForRendering()
98 * @dataProvider provideGetLanguageForRendering
100 * @param string|null $expected Expected language code
101 * @param string $wikiLangCode Wiki language code
102 * @param string|null $lang lang=... URL parameter
104 public function testGetLanguageForRendering( $expected = null, $wikiLangCode, $lang = null ) {
106 if ( $lang !== null ) {
107 $params['lang'] = $lang;
109 $request = new FauxRequest( $params );
110 $this->setMwGlobals( 'wgLanguageCode', $wikiLangCode );
112 $page = $this->getImagePage( 'translated.svg' );
113 $page = TestingAccessWrapper
::newFromObject( $page );
115 /** @var ImagePage $page */
116 $result = $page->getLanguageForRendering( $request, $page->getDisplayedFile() );
117 $this->assertEquals( $expected, $result );
120 public function provideGetLanguageForRendering() {
123 [ 'ru', 'ru', 'ru' ],
126 [ null, 'en', 'en' ],
127 [ null, 'fr', 'fr' ],
128 [ null, 'ru', 'en' ],
129 [ 'de', 'ru', 'de' ],