Merge "Make JSON styling available on mobile"
[lhc/web/wiklou.git] / tests / phpunit / includes / page / ImagePageTest.php
index 2b30cfa..7e43ce4 100644 (file)
@@ -1,7 +1,10 @@
 <?php
+
+use Wikimedia\TestingAccessWrapper;
+
 class ImagePageTest extends MediaWikiMediaTestCase {
 
-       function setUp() {
+       public function setUp() {
                $this->setMwGlobals( 'wgImageLimits', [
                        [ 320, 240 ],
                        [ 640, 480 ],
@@ -12,7 +15,7 @@ class ImagePageTest extends MediaWikiMediaTestCase {
                parent::setUp();
        }
 
-       function getImagePage( $filename ) {
+       public function getImagePage( $filename ) {
                $title = Title::makeTitleSafe( NS_FILE, $filename );
                $file = $this->dataFile( $filename );
                $iPage = new ImagePage( $title );
@@ -21,11 +24,12 @@ class ImagePageTest extends MediaWikiMediaTestCase {
        }
 
        /**
+        * @covers ImagePage::getDisplayWidthHeight
         * @dataProvider providerGetDisplayWidthHeight
         * @param array $dim Array [maxWidth, maxHeight, width, height]
         * @param array $expected Array [width, height] The width and height we expect to display at
         */
-       function testGetDisplayWidthHeight( $dim, $expected ) {
+       public function testGetDisplayWidthHeight( $dim, $expected ) {
                $iPage = $this->getImagePage( 'animated.gif' );
                $reflection = new ReflectionClass( $iPage );
                $reflMethod = $reflection->getMethod( 'getDisplayWidthHeight' );
@@ -35,7 +39,7 @@ class ImagePageTest extends MediaWikiMediaTestCase {
                $this->assertEquals( $actual, $expected );
        }
 
-       function providerGetDisplayWidthHeight() {
+       public function providerGetDisplayWidthHeight() {
                return [
                        [
                                [ 1024.0, 768.0, 600.0, 600.0 ],
@@ -65,11 +69,12 @@ class ImagePageTest extends MediaWikiMediaTestCase {
        }
 
        /**
+        * @covers ImagePage::getThumbSizes
         * @dataProvider providerGetThumbSizes
         * @param string $filename
         * @param int $expectedNumberThumbs How many thumbnails to show
         */
-       function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
+       public function testGetThumbSizes( $filename, $expectedNumberThumbs ) {
                $iPage = $this->getImagePage( $filename );
                $reflection = new ReflectionClass( $iPage );
                $reflMethod = $reflection->getMethod( 'getThumbSizes' );
@@ -79,7 +84,7 @@ class ImagePageTest extends MediaWikiMediaTestCase {
                $this->assertEquals( count( $actual ), $expectedNumberThumbs );
        }
 
-       function providerGetThumbSizes() {
+       public function providerGetThumbSizes() {
                return [
                        [ 'animated.gif', 2 ],
                        [ 'Toll_Texas_1.svg', 1 ],
@@ -87,4 +92,41 @@ class ImagePageTest extends MediaWikiMediaTestCase {
                        [ 'jpeg-comment-binary.jpg', 2 ],
                ];
        }
+
+       /**
+        * @covers ImagePage::getLanguageForRendering()
+        * @dataProvider provideGetLanguageForRendering
+        *
+        * @param string|null $expected Expected language code
+        * @param string $wikiLangCode Wiki language code
+        * @param string|null $lang lang=... URL parameter
+        */
+       public function testGetLanguageForRendering( $expected = null, $wikiLangCode, $lang = null ) {
+               $params = [];
+               if ( $lang !== null ) {
+                       $params['lang'] = $lang;
+               }
+               $request = new FauxRequest( $params );
+               $this->setMwGlobals( 'wgLanguageCode', $wikiLangCode );
+
+               $page = $this->getImagePage( 'translated.svg' );
+               $page = TestingAccessWrapper::newFromObject( $page );
+
+               /** @var ImagePage $page */
+               $result = $page->getLanguageForRendering( $request, $page->getDisplayedFile() );
+               $this->assertEquals( $expected, $result );
+       }
+
+       public function provideGetLanguageForRendering() {
+               return [
+                       [ 'ru', 'ru' ],
+                       [ 'ru', 'ru', 'ru' ],
+                       [ null, 'en' ],
+                       [ null, 'fr' ],
+                       [ null, 'en', 'en' ],
+                       [ null, 'fr', 'fr' ],
+                       [ null, 'ru', 'en' ],
+                       [ 'de', 'ru', 'de' ],
+               ];
+       }
 }