resourceloader: Remove unused static SkinModule::getLogo method
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 20 Aug 2018 23:58:41 +0000 (00:58 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 28 Aug 2018 22:50:50 +0000 (23:50 +0100)
This existed for internal use by OutputPage, which is no longer
the case as of I11b390f2e4f5e7db.

Also move the unit tests from OutputPageTest,
to ResourceLoaderSkinModuleTest.

Change-Id: I8b23f976f5f89b1005b387a827f75031f5c96141

includes/resourceloader/ResourceLoaderSkinModule.php
tests/phpunit/includes/OutputPageTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php

index 69313bf..2455596 100644 (file)
@@ -176,25 +176,14 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
        }
 
        /**
-        * Non-static proxy to ::getLogo (for overloading in sub classes or tests).
-        *
-        * @codeCoverageIgnore
         * @since 1.31
-        * @param Config $conf
-        * @return string|array
-        */
-       protected function getLogoData( Config $conf ) {
-               return static::getLogo( $conf );
-       }
-
-       /**
         * @param Config $conf
         * @return string|array Single url if no variants are defined,
         *  or an array of logo urls keyed by dppx in form "<float>x".
         *  Key "1x" is always defined. Key "svg" may also be defined,
         *  in which case variants other than "1x" are omitted.
         */
-       public static function getLogo( Config $conf ) {
+       protected function getLogoData( Config $conf ) {
                $logo = $conf->get( 'Logo' );
                $logoHD = $conf->get( 'LogoHD' );
 
index 1f3ee27..42ea9ed 100644 (file)
@@ -2037,82 +2037,6 @@ class OutputPageTest extends MediaWikiTestCase {
                ] );
        }
 
-       /**
-        * @dataProvider providePreloadLinkHeaders
-        * @covers ResourceLoaderSkinModule::getPreloadLinks
-        * @covers ResourceLoaderSkinModule::getLogoPreloadlinks
-        * @covers ResourceLoaderSkinModule::getLogo
-        */
-       public function testPreloadLinkHeaders( $config, $result ) {
-               $this->setMwGlobals( $config );
-               $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
-                       ->disableOriginalConstructor()->getMock();
-               $module = new ResourceLoaderSkinModule();
-
-               $this->assertEquals( [ $result ], $module->getHeaders( $ctx ) );
-       }
-
-       public function providePreloadLinkHeaders() {
-               return [
-                       [
-                               [
-                                       'wgResourceBasePath' => '/w',
-                                       'wgLogo' => '/img/default.png',
-                                       'wgLogoHD' => [
-                                               '1.5x' => '/img/one-point-five.png',
-                                               '2x' => '/img/two-x.png',
-                                       ],
-                               ],
-                               'Link: </img/default.png>;rel=preload;as=image;media=' .
-                               'not all and (min-resolution: 1.5dppx),' .
-                               '</img/one-point-five.png>;rel=preload;as=image;media=' .
-                               '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' .
-                               '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
-                       ],
-                       [
-                               [
-                                       'wgResourceBasePath' => '/w',
-                                       'wgLogo' => '/img/default.png',
-                                       'wgLogoHD' => false,
-                               ],
-                               'Link: </img/default.png>;rel=preload;as=image'
-                       ],
-                       [
-                               [
-                                       'wgResourceBasePath' => '/w',
-                                       'wgLogo' => '/img/default.png',
-                                       'wgLogoHD' => [
-                                               '2x' => '/img/two-x.png',
-                                       ],
-                               ],
-                               'Link: </img/default.png>;rel=preload;as=image;media=' .
-                               'not all and (min-resolution: 2dppx),' .
-                               '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
-                       ],
-                       [
-                               [
-                                       'wgResourceBasePath' => '/w',
-                                       'wgLogo' => '/img/default.png',
-                                       'wgLogoHD' => [
-                                               'svg' => '/img/vector.svg',
-                                       ],
-                               ],
-                               'Link: </img/vector.svg>;rel=preload;as=image'
-
-                       ],
-                       [
-                               [
-                                       'wgResourceBasePath' => '/w',
-                                       'wgLogo' => '/w/test.jpg',
-                                       'wgLogoHD' => false,
-                                       'wgUploadPath' => '/w/images',
-                                       'IP' => dirname( __DIR__ ) . '/data/media',
-                               ],
-                               'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
-                       ],
-               ];
-       }
-
        /**
         * @return OutputPage
         */
index 61ab8a5..231979d 100644 (file)
@@ -1,9 +1,11 @@
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 /**
  * @group ResourceLoader
  */
-class ResourceLoaderSkinModuleTest extends PHPUnit\Framework\TestCase {
+class ResourceLoaderSkinModuleTest extends MediaWikiTestCase {
 
        use MediaWikiCoversValidator;
 
@@ -107,25 +109,23 @@ CSS
        }
 
        /**
-        * @dataProvider provideGetLogo
-        * @covers ResourceLoaderSkinModule::getLogo
+        * @dataProvider provideGetLogoData
+        * @covers ResourceLoaderSkinModule::getLogoData
         */
-       public function testGetLogo( $config, $expected, $baseDir = null ) {
+       public function testGetLogoData( $config, $expected, $baseDir = null ) {
                if ( $baseDir ) {
-                       $oldIP = $GLOBALS['IP'];
-                       $GLOBALS['IP'] = $baseDir;
-                       $teardown = new Wikimedia\ScopedCallback( function () use ( $oldIP ) {
-                               $GLOBALS['IP'] = $oldIP;
-                       } );
+                       $this->setMwGlobals( 'IP', $baseDir );
                }
+               // Allow testing of protected method
+               $module = TestingAccessWrapper::newFromObject( new ResourceLoaderSkinModule() );
 
                $this->assertEquals(
                        $expected,
-                       ResourceLoaderSkinModule::getLogo( new HashConfig( $config ) )
+                       $module->getLogoData( new HashConfig( $config ) )
                );
        }
 
-       public function provideGetLogo() {
+       public function provideGetLogoData() {
                return [
                        'simple' => [
                                'config' => [
@@ -203,4 +203,80 @@ CSS
                        ],
                ];
        }
+
+       /**
+        * @dataProvider providePreloadLinks
+        * @covers ResourceLoaderSkinModule::getPreloadLinks
+        * @covers ResourceLoaderSkinModule::getLogoPreloadlinks
+        * @covers ResourceLoaderSkinModule::getLogoData
+        */
+       public function testPreloadLinkHeaders( $config, $result ) {
+               $this->setMwGlobals( $config );
+               $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
+                       ->disableOriginalConstructor()->getMock();
+               $module = new ResourceLoaderSkinModule();
+
+               $this->assertEquals( [ $result ], $module->getHeaders( $ctx ) );
+       }
+
+       public function providePreloadLinks() {
+               return [
+                       [
+                               [
+                                       'wgResourceBasePath' => '/w',
+                                       'wgLogo' => '/img/default.png',
+                                       'wgLogoHD' => [
+                                               '1.5x' => '/img/one-point-five.png',
+                                               '2x' => '/img/two-x.png',
+                                       ],
+                               ],
+                               'Link: </img/default.png>;rel=preload;as=image;media=' .
+                               'not all and (min-resolution: 1.5dppx),' .
+                               '</img/one-point-five.png>;rel=preload;as=image;media=' .
+                               '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' .
+                               '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
+                       ],
+                       [
+                               [
+                                       'wgResourceBasePath' => '/w',
+                                       'wgLogo' => '/img/default.png',
+                                       'wgLogoHD' => false,
+                               ],
+                               'Link: </img/default.png>;rel=preload;as=image'
+                       ],
+                       [
+                               [
+                                       'wgResourceBasePath' => '/w',
+                                       'wgLogo' => '/img/default.png',
+                                       'wgLogoHD' => [
+                                               '2x' => '/img/two-x.png',
+                                       ],
+                               ],
+                               'Link: </img/default.png>;rel=preload;as=image;media=' .
+                               'not all and (min-resolution: 2dppx),' .
+                               '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
+                       ],
+                       [
+                               [
+                                       'wgResourceBasePath' => '/w',
+                                       'wgLogo' => '/img/default.png',
+                                       'wgLogoHD' => [
+                                               'svg' => '/img/vector.svg',
+                                       ],
+                               ],
+                               'Link: </img/vector.svg>;rel=preload;as=image'
+
+                       ],
+                       [
+                               [
+                                       'wgResourceBasePath' => '/w',
+                                       'wgLogo' => '/w/test.jpg',
+                                       'wgLogoHD' => false,
+                                       'wgUploadPath' => '/w/images',
+                                       'IP' => dirname( dirname( __DIR__ ) ) . '/data/media',
+                               ],
+                               'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
+                       ],
+               ];
+       }
 }