resourceloader: Add missing Module->setConfig() calls in tests and installer
There is a fallback in Module->getConfig() to the global services container. This is not meant to be used in practice, but there were two places where this was missing: WebInstallerOutput, and various PHPUnit tests. * Add missing setConfig() to WebInstallerOutput. * Add missing setConfig() to various tests. Most tests were already doing this correctly and using the standard mock from ResourceLoaderTestCase. Upon switching the last few tests as well, I uncovered various errors due to the mock missing some settings that the tested code uses, so these have been added now to ResourceLoaderTestCase. Bug: T277728 Change-Id: I44f16ec4e00423fb6f641e58fffc1d40e4571f01
This commit is contained in:
parent
b36f5a4175
commit
b7c70526a9
8 changed files with 49 additions and 32 deletions
|
|
@ -148,6 +148,7 @@ class WebInstallerOutput {
|
|||
'mw-config/config.css',
|
||||
],
|
||||
] );
|
||||
$module->setConfig( $resourceLoader->getConfig() );
|
||||
|
||||
// Based on: ResourceLoaderFileModule::getStyles (without the DB query)
|
||||
$styles = ResourceLoader::makeCombinedStyles(
|
||||
|
|
|
|||
|
|
@ -355,8 +355,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
|||
|
||||
$startupCode = file_get_contents( "$IP/resources/src/startup/startup.js" );
|
||||
|
||||
// The files read here MUST be kept in sync with maintenance/jsduck/eg-iframe.html,
|
||||
// and MUST be considered by 'fileHashes' in StartUpModule::getDefinitionSummary().
|
||||
// The files read here MUST be kept in sync with maintenance/jsduck/eg-iframe.html.
|
||||
$mwLoaderCode = file_get_contents( "$IP/resources/src/startup/mediawiki.js" ) .
|
||||
file_get_contents( "$IP/resources/src/startup/mediawiki.requestIdleCallback.js" );
|
||||
if ( $conf->get( 'ResourceLoaderEnableJSProfiler' ) ) {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,12 @@ abstract class ResourceLoaderTestCase extends MediaWikiIntegrationTestCase {
|
|||
// For ResourceLoader::inDebugMode since it doesn't have context
|
||||
'ResourceLoaderDebug' => true,
|
||||
|
||||
// For ResourceLoaderModule
|
||||
'ResourceLoaderValidateJS' => false,
|
||||
|
||||
// For ResourceLoaderWikiModule
|
||||
'MaxRedirects' => 1,
|
||||
|
||||
// For ResourceLoaderSkinModule
|
||||
'Logos' => false,
|
||||
'Logo' => '/logo.png',
|
||||
|
|
@ -69,6 +75,8 @@ abstract class ResourceLoaderTestCase extends MediaWikiIntegrationTestCase {
|
|||
'ScriptPath' => '/w',
|
||||
'Script' => '/w/index.php',
|
||||
'LoadScript' => '/w/load.php',
|
||||
'EnableJavaScriptTest' => false,
|
||||
'ResourceLoaderEnableJSProfiler' => false,
|
||||
|
||||
// For ResourceLoader::respond() - TODO: Inject somehow T32956
|
||||
'UseFileCache' => false,
|
||||
|
|
|
|||
|
|
@ -2962,11 +2962,13 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
|
|||
* @covers ResourceLoaderSkinModule::getPreloadLinks
|
||||
* @covers ResourceLoaderSkinModule::getLogoPreloadlinks
|
||||
*/
|
||||
public function testPreloadLinkHeaders( $config, $result ) {
|
||||
$this->setMwGlobals( $config );
|
||||
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
|
||||
->disableOriginalConstructor()->getMock();
|
||||
public function testPreloadLinkHeaders( $config, $result, $installPath = null ) {
|
||||
if ( $installPath ) {
|
||||
$this->setMwGlobals( [ 'IP' => $installPath ] );
|
||||
}
|
||||
$ctx = $this->createMock( ResourceLoaderContext::class );
|
||||
$module = new ResourceLoaderSkinModule();
|
||||
$module->setConfig( new HashConfig( $config + ResourceLoaderTestCase::getSettings() ) );
|
||||
|
||||
$this->assertEquals( [ $result ], $module->getHeaders( $ctx ) );
|
||||
}
|
||||
|
|
@ -2975,9 +2977,9 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
|
|||
return [
|
||||
[
|
||||
[
|
||||
'wgResourceBasePath' => '/w',
|
||||
'wgLogo' => '/img/default.png',
|
||||
'wgLogos' => [
|
||||
'ResourceBasePath' => '/w',
|
||||
'Logo' => '/img/default.png',
|
||||
'Logos' => [
|
||||
'1.5x' => '/img/one-point-five.png',
|
||||
'2x' => '/img/two-x.png',
|
||||
],
|
||||
|
|
@ -2990,8 +2992,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
[
|
||||
[
|
||||
'wgResourceBasePath' => '/w',
|
||||
'wgLogos' => [
|
||||
'ResourceBasePath' => '/w',
|
||||
'Logos' => [
|
||||
'1x' => '/img/default.png',
|
||||
],
|
||||
],
|
||||
|
|
@ -2999,8 +3001,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
[
|
||||
[
|
||||
'wgResourceBasePath' => '/w',
|
||||
'wgLogos' => [
|
||||
'ResourceBasePath' => '/w',
|
||||
'Logos' => [
|
||||
'1x' => '/img/default.png',
|
||||
'2x' => '/img/two-x.png',
|
||||
],
|
||||
|
|
@ -3011,8 +3013,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
[
|
||||
[
|
||||
'wgResourceBasePath' => '/w',
|
||||
'wgLogos' => [
|
||||
'ResourceBasePath' => '/w',
|
||||
'Logos' => [
|
||||
'1x' => '/img/default.png',
|
||||
'svg' => '/img/vector.svg',
|
||||
],
|
||||
|
|
@ -3022,14 +3024,14 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
[
|
||||
[
|
||||
'wgResourceBasePath' => '/w',
|
||||
'wgLogos' => [
|
||||
'ResourceBasePath' => '/w',
|
||||
'Logos' => [
|
||||
'1x' => '/w/test.jpg',
|
||||
],
|
||||
'wgUploadPath' => '/w/images',
|
||||
'IP' => dirname( __DIR__ ) . '/data/media',
|
||||
'UploadPath' => '/w/images',
|
||||
],
|
||||
'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
|
||||
dirname( __DIR__ ) . '/data/media',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -526,8 +526,10 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
|
|||
$context = $this->getResourceLoaderContext();
|
||||
|
||||
$moduleA = new ResourceLoaderFileTestModule( $a );
|
||||
$moduleA->setConfig( $context->getResourceLoader()->getConfig() );
|
||||
$versionA = $moduleA->getVersionHash( $context );
|
||||
$moduleB = new ResourceLoaderFileTestModule( $b );
|
||||
$moduleB->setConfig( $context->getResourceLoader()->getConfig() );
|
||||
$versionB = $moduleB->getVersionHash( $context );
|
||||
|
||||
$this->assertSame(
|
||||
|
|
@ -855,6 +857,7 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
|
|||
public function testGetScriptPackageFiles( $moduleDefinition, $expected, $contextOptions = [] ) {
|
||||
$module = new ResourceLoaderFileModule( $moduleDefinition );
|
||||
$context = $this->getResourceLoaderContext( $contextOptions );
|
||||
$module->setConfig( $context->getResourceLoader()->getConfig() );
|
||||
if ( isset( $moduleDefinition['name'] ) ) {
|
||||
$module->setName( $moduleDefinition['name'] );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,7 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
|
|||
'mayValidateScript' => true,
|
||||
'script' => "var a = 'this is';\n {\ninvalid"
|
||||
] );
|
||||
$module->setConfig( $context->getResourceLoader()->getConfig() );
|
||||
$this->assertEquals(
|
||||
'mw.log.error(' .
|
||||
'"JavaScript parse error (scripts need to be valid ECMAScript 5): ' .
|
||||
|
|
|
|||
|
|
@ -707,6 +707,7 @@ mw.loader.register([
|
|||
}
|
||||
$rl->register( $case['modules'] );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl->getConfig() );
|
||||
$out = ltrim( $case['out'], "\n" );
|
||||
|
||||
// Disable log from getModuleRegistrations via MWExceptionHandler
|
||||
|
|
@ -751,6 +752,7 @@ mw.loader.register([
|
|||
$rl = $context->getResourceLoader();
|
||||
$rl->register( $modules );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl->getConfig() );
|
||||
$out = 'mw.loader.addSource({"local":"/w/load.php"});' . "\n"
|
||||
. 'mw.loader.register(['
|
||||
. '["test.blank","{blankVer}"],'
|
||||
|
|
@ -776,6 +778,7 @@ mw.loader.register([
|
|||
$rl = $context->getResourceLoader();
|
||||
$rl->register( $modules );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl->getConfig() );
|
||||
$out =
|
||||
'mw.loader.addSource({
|
||||
"local": "/w/load.php"
|
||||
|
|
@ -805,32 +808,24 @@ mw.loader.register([
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ResourceLoaderStartupModule::getDefinitionSummary
|
||||
* @covers ResourceLoaderStartupModule
|
||||
*/
|
||||
public function testGetVersionHash_varyConfig() {
|
||||
$context = $this->getResourceLoaderContext();
|
||||
|
||||
$this->setMwGlobals( 'wgArticlePath', '/w1' );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $context->getResourceLoader()->getConfig() );
|
||||
$version1 = $module->getVersionHash( $context );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$version2 = $module->getVersionHash( $context );
|
||||
|
||||
$this->setMwGlobals( 'wgArticlePath', '/w3' );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$version3 = $module->getVersionHash( $context );
|
||||
$module->setConfig( $context->getResourceLoader()->getConfig() );
|
||||
$version2 = $module->getVersionHash( $context );
|
||||
|
||||
$this->assertEquals(
|
||||
$version1,
|
||||
$version2,
|
||||
'Deterministic version hash'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$version1,
|
||||
$version3,
|
||||
'Config change no longer impacts version hash'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -844,6 +839,7 @@ mw.loader.register([
|
|||
'test.b' => [ 'class' => ResourceLoaderTestModule::class ],
|
||||
] );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl1->getConfig() );
|
||||
$version1 = $module->getVersionHash( $context1 );
|
||||
|
||||
$context2 = $this->getResourceLoaderContext();
|
||||
|
|
@ -853,6 +849,7 @@ mw.loader.register([
|
|||
'test.c' => [ 'class' => ResourceLoaderTestModule::class ],
|
||||
] );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl2->getConfig() );
|
||||
$version2 = $module->getVersionHash( $context2 );
|
||||
|
||||
$context3 = $this->getResourceLoaderContext();
|
||||
|
|
@ -865,6 +862,7 @@ mw.loader.register([
|
|||
],
|
||||
] );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl3->getConfig() );
|
||||
$version3 = $module->getVersionHash( $context3 );
|
||||
|
||||
// Module name *is* significant (T201686)
|
||||
|
|
@ -894,6 +892,7 @@ mw.loader.register([
|
|||
],
|
||||
] );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl->getConfig() );
|
||||
$version1 = $module->getVersionHash( $context );
|
||||
|
||||
$context = $this->getResourceLoaderContext();
|
||||
|
|
@ -905,6 +904,7 @@ mw.loader.register([
|
|||
],
|
||||
] );
|
||||
$module = new ResourceLoaderStartUpModule();
|
||||
$module->setConfig( $rl->getConfig() );
|
||||
$version2 = $module->getVersionHash( $context );
|
||||
|
||||
// Dependencies *are* significant (T201686)
|
||||
|
|
|
|||
|
|
@ -377,12 +377,14 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
|
|||
'MediaWiki:Common.css' => [ 'type' => 'style' ],
|
||||
];
|
||||
|
||||
$rl = new EmptyResourceLoader();
|
||||
|
||||
$module = $this->getMockBuilder( ResourceLoaderWikiModule::class )
|
||||
->onlyMethods( [ 'getPages' ] )
|
||||
->getMock();
|
||||
$module->method( 'getPages' )->willReturn( $pages );
|
||||
$module->setConfig( $rl->getConfig() );
|
||||
|
||||
$rl = new EmptyResourceLoader();
|
||||
$context = new DerivativeResourceLoaderContext(
|
||||
new ResourceLoaderContext( $rl, new FauxRequest() )
|
||||
);
|
||||
|
|
@ -421,6 +423,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
|
|||
->willReturn( [
|
||||
'MediaWiki:Redirect.js' => [ 'type' => 'script' ]
|
||||
] );
|
||||
$module->setConfig( $context->getResourceLoader()->getConfig() );
|
||||
$context->setContentOverrideCallback( static function ( PageIdentity $title ) {
|
||||
if ( $title->getDBkey() === 'Redirect.js' ) {
|
||||
$handler = new JavaScriptContentHandler();
|
||||
|
|
|
|||
Loading…
Reference in a new issue