From: jenkins-bot Date: Mon, 28 May 2018 11:36:32 +0000 (+0000) Subject: Merge "resourceloader: Include global LESS variables in LESS cache key" X-Git-Tag: 1.34.0-rc.0~5275 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=474daae531738ff6b517ccfffbdaf850512e871b;hp=-c Merge "resourceloader: Include global LESS variables in LESS cache key" --- 474daae531738ff6b517ccfffbdaf850512e871b diff --combined includes/resourceloader/ResourceLoader.php index bb7207d6df,1cbd8781ae..1b8a4a8648 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@@ -1504,7 -1504,7 +1504,7 @@@ MESSAGE * * @param string $script JavaScript code * @param string $nonce [optional] Content-Security-Policy nonce (from OutputPage::getCSPNonce) - * @return WrappedString HTML + * @return string|WrappedString HTML */ public static function makeInlineScript( $script, $nonce = null ) { $js = self::makeLoaderConditionalScript( $script ); @@@ -1704,12 -1704,13 +1704,13 @@@ * Returns LESS compiler set up for use with MediaWiki * * @since 1.27 - * @param array $extraVars Associative array of extra (i.e., other than the - * globally-configured ones) that should be used for compilation. + * @param array $vars Associative array of variables that should be used + * for compilation. Since 1.32, this method no longer automatically includes + * global LESS vars from ResourceLoader::getLessVars (T191937). * @throws MWException * @return Less_Parser */ - public function getLessCompiler( $extraVars = [] ) { + public function getLessCompiler( $vars = [] ) { // When called from the installer, it is possible that a required PHP extension // is missing (at least for now; see T49564). If this is the case, throw an // exception (caught by the installer) to prevent a fatal error later on. @@@ -1718,7 -1719,7 +1719,7 @@@ } $parser = new Less_Parser; - $parser->ModifyVars( array_merge( $this->getLessVars(), $extraVars ) ); + $parser->ModifyVars( $vars ); $parser->SetImportDirs( array_fill_keys( $this->config->get( 'ResourceLoaderLESSImportPaths' ), '' ) ); diff --combined tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index 2fea7f30cc,7c2476f9cf..71a6339536 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@@ -267,7 -267,7 +267,7 @@@ class ResourceLoaderTest extends Resour */ public function testLessImportDirs() { $rl = new EmptyResourceLoader(); - $lc = $rl->getLessCompiler(); + $lc = $rl->getLessCompiler( $rl->getLessVars() ); $basePath = dirname( dirname( __DIR__ ) ) . '/data/less'; $lc->SetImportDirs( [ "$basePath/common" => '', @@@ -596,11 -596,11 +596,11 @@@ mw.example() } } - protected function getFailFerryMock() { + protected function getFailFerryMock( $getter = 'getScript' ) { $mock = $this->getMockBuilder( ResourceLoaderTestModule::class ) - ->setMethods( [ 'getScript' ] ) + ->setMethods( [ $getter ] ) ->getMock(); - $mock->method( 'getScript' )->will( $this->throwException( + $mock->method( $getter )->will( $this->throwException( new Exception( 'Ferry not found' ) ) ); return $mock; @@@ -614,14 -614,6 +614,14 @@@ return $mock; } + protected function getSimpleStyleModuleMock( $styles = '' ) { + $mock = $this->getMockBuilder( ResourceLoaderTestModule::class ) + ->setMethods( [ 'getStyles' ] ) + ->getMock(); + $mock->method( 'getStyles' )->willReturn( [ '' => $styles ] ); + return $mock; + } + /** * @covers ResourceLoader::getCombinedVersion */ @@@ -778,43 -770,6 +778,43 @@@ ); } + /** + * Verify that exceptions in PHP for one module will not break others + * (stylesheet response). + * + * @covers ResourceLoader::makeModuleResponse + */ + public function testMakeModuleResponseErrorCSS() { + $modules = [ + 'foo' => self::getSimpleStyleModuleMock( '.foo{}' ), + 'ferry' => self::getFailFerryMock( 'getStyles' ), + 'bar' => self::getSimpleStyleModuleMock( '.bar{}' ), + ]; + $rl = new EmptyResourceLoader(); + $rl->register( $modules ); + $context = $this->getResourceLoaderContext( + [ + 'modules' => 'foo|ferry|bar', + 'only' => 'styles', + 'debug' => 'false', + ], + $rl + ); + + // Disable log from makeModuleResponse via outputErrorAndLog + $this->setLogger( 'exception', new Psr\Log\NullLogger() ); + + $response = $rl->makeModuleResponse( $context, $modules ); + $errors = $rl->getErrors(); + + $this->assertCount( 2, $errors ); + $this->assertRegExp( '/Ferry not found/', $errors[0] ); + $this->assertRegExp( '/Problem.+\n\s*"ferry":\s*"error"/m', $errors[1] ); + $this->assertEquals( + '.foo{}.bar{}', + $response + ); + } /** * Verify that when building the startup module response, * an exception from one module class will not break the entire