resourceloader: Move registering of custom sources to ServiceWiring
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 29 Mar 2019 01:21:18 +0000 (01:21 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 29 Mar 2019 01:46:34 +0000 (01:46 +0000)
Remove the now-redundant mocking of this configuration from various
test classes.

Bug: T32956
Change-Id: If90a10a76b8289c4ba707382ac915441c17d831f

includes/ServiceWiring.php
includes/resourceloader/ResourceLoader.php
tests/phpunit/ResourceLoaderTestCase.php
tests/phpunit/includes/resourceloader/ResourceLoaderClientHtmlTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 73e4543..b1cdc81 100644 (file)
@@ -417,10 +417,15 @@ return [
        },
 
        'ResourceLoader' => function ( MediaWikiServices $services ) : ResourceLoader {
-               return new ResourceLoader(
-                       $services->getMainConfig(),
+               $config = $services->getMainConfig();
+
+               $rl = new ResourceLoader(
+                       $config,
                        LoggerFactory::getInstance( 'resourceloader' )
                );
+               $rl->addSource( $config->get( 'ResourceLoaderSources' ) );
+
+               return $rl;
        },
 
        'RevisionFactory' => function ( MediaWikiServices $services ) : RevisionFactory {
index 5712692..8ab7c0c 100644 (file)
@@ -254,9 +254,6 @@ class ResourceLoader implements LoggerAwareInterface {
                // Add 'local' source first
                $this->addSource( 'local', $config->get( 'LoadScript' ) );
 
-               // Add other sources
-               $this->addSource( $config->get( 'ResourceLoaderSources' ) );
-
                // Register core modules
                $this->register( include "$IP/resources/Resources.php" );
                // Register extension modules
index ca5ff6c..c7fb48b 100644 (file)
@@ -60,9 +60,6 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase {
                        // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
                        'CacheEpoch' => '20140101000000',
 
-                       // For ResourceLoader::__construct()
-                       'ResourceLoaderSources' => [],
-
                        // For wfScript()
                        'ScriptPath' => '/w',
                        'Script' => '/w/index.php',
index 50b9421..0166796 100644 (file)
@@ -17,7 +17,6 @@ class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
 
        protected static function makeContext( $extraQuery = [] ) {
                $conf = new HashConfig( [
-                       'ResourceLoaderSources' => [],
                        'ResourceModuleSkinStyles' => [],
                        'ResourceModules' => [],
                        'EnableJavaScriptTest' => false,
index 2ee85b5..d4b5ed6 100644 (file)
@@ -459,13 +459,12 @@ mw.loader.register( [
         * @covers ResourceLoader::makeLoaderRegisterScript
         */
        public function testGetModuleRegistrations( $case ) {
-               if ( isset( $case['sources'] ) ) {
-                       $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
-               }
-
                $extraQuery = $case['extraQuery'] ?? [];
                $context = $this->getResourceLoaderContext( $extraQuery );
                $rl = $context->getResourceLoader();
+               if ( isset( $case['sources'] ) ) {
+                       $rl->addSource( $case['sources'] );
+               }
                $rl->register( $case['modules'] );
                $module = new ResourceLoaderStartUpModule();
                $out = ltrim( $case['out'], "\n" );
index 5941c6e..3f7925f 100644 (file)
@@ -624,7 +624,6 @@ END
         * @covers ResourceLoader::getLoadScript
         */
        public function testGetLoadScript() {
-               $this->setMwGlobals( 'wgResourceLoaderSources', [] );
                $rl = new ResourceLoader();
                $sources = self::fakeSources();
                $rl->addSource( $sources );