2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2014-03-07 17:18:31 +00:00
|
|
|
class ResourceLoaderTest extends ResourceLoaderTestCase {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
Support LESS stylesheets in ResourceLoader
This patch adds support for the LESS stylesheet language to ResourceLoader.
LESS is a stylesheet language that compiles into CSS. The patch includes
lessphp, a LESS compiler implemented in PHP. The rationale for choosing LESS is
explained in a MediaWiki RFC which accompanies this patch, available at
<https://www.mediawiki.org/wiki/Requests_for_comment/LESS>.
LESS support is provided for ResourceLoader file modules. It is triggered by
the presence of the '.less' extension in stylesheet filenames. LESS files are
compiled by lessc, and the resultant CSS is subjected to the standard set of
transformations (CSSJanus & CSSMin). The immediate result of LESS compilation
is encoded as an array, which includes the list of LESS files that were
compiled and their mtimes. This array is cached. Cache invalidation is
performed by comparing the cached mtimes with the mtimes of the files on disk.
If the compiler itself throws an exception, ResourceLoader constructs a
compilation result which consists of the error message encoded as a CSS
comment. Failed compilation results are cached too, but with an expiration time
of five minutes. The expiration time is required because the full list of
referenced files is not known.
Three configuration variables configure the global environment for LESS
modules: $wgResourceLoaderLESSVars, $wgResourceLoaderLESSFunctions, and
$wgResourceLoaderLESSImportPaths. $wgResourceLoaderLESSVars maps variable names
to CSS values, specified as strings. Variables declared in this array are
available in all LESS files. $wgResourceLoaderLESSFunctions is similar, except
it maps custom function names to PHP callables. These functions can be called
from within LESS to transform values. Read more about custom functions at
<http://leafo.net/lessphp/docs/#custom_functions>. Finally,
$wgResourceLoaderLESSImportPaths specifies file system paths in addition to the
current module's path where the LESS compiler should look up files referenced
in @import statements.
The issue of handling of /* @embed */ and /* @noflip */ annotations is left
unresolved. Earlier versions of this patch included an @embed analog
implemented as a LESS custom function, but there was enough ambiguity about
whether the strategy it took was optimal to merit discussing it in a separate,
follow-up patch.
Bug: 40964
Change-Id: Id052a04dd2f76a1f4aef39fbd454bd67f5fd282f
2013-08-11 16:40:20 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
|
|
|
|
'wgResourceLoaderLESSImportPaths' => [
|
2015-06-16 19:06:19 +00:00
|
|
|
dirname( dirname( __DIR__ ) ) . '/data/less/common',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'wgResourceLoaderLESSVars' => [
|
Support LESS stylesheets in ResourceLoader
This patch adds support for the LESS stylesheet language to ResourceLoader.
LESS is a stylesheet language that compiles into CSS. The patch includes
lessphp, a LESS compiler implemented in PHP. The rationale for choosing LESS is
explained in a MediaWiki RFC which accompanies this patch, available at
<https://www.mediawiki.org/wiki/Requests_for_comment/LESS>.
LESS support is provided for ResourceLoader file modules. It is triggered by
the presence of the '.less' extension in stylesheet filenames. LESS files are
compiled by lessc, and the resultant CSS is subjected to the standard set of
transformations (CSSJanus & CSSMin). The immediate result of LESS compilation
is encoded as an array, which includes the list of LESS files that were
compiled and their mtimes. This array is cached. Cache invalidation is
performed by comparing the cached mtimes with the mtimes of the files on disk.
If the compiler itself throws an exception, ResourceLoader constructs a
compilation result which consists of the error message encoded as a CSS
comment. Failed compilation results are cached too, but with an expiration time
of five minutes. The expiration time is required because the full list of
referenced files is not known.
Three configuration variables configure the global environment for LESS
modules: $wgResourceLoaderLESSVars, $wgResourceLoaderLESSFunctions, and
$wgResourceLoaderLESSImportPaths. $wgResourceLoaderLESSVars maps variable names
to CSS values, specified as strings. Variables declared in this array are
available in all LESS files. $wgResourceLoaderLESSFunctions is similar, except
it maps custom function names to PHP callables. These functions can be called
from within LESS to transform values. Read more about custom functions at
<http://leafo.net/lessphp/docs/#custom_functions>. Finally,
$wgResourceLoaderLESSImportPaths specifies file system paths in addition to the
current module's path where the LESS compiler should look up files referenced
in @import statements.
The issue of handling of /* @embed */ and /* @noflip */ annotations is left
unresolved. Earlier versions of this patch included an @embed analog
implemented as a LESS custom function, but there was enough ambiguity about
whether the strategy it took was optimal to merit discussing it in a separate,
follow-up patch.
Bug: 40964
Change-Id: Id052a04dd2f76a1f4aef39fbd454bd67f5fd282f
2013-08-11 16:40:20 +00:00
|
|
|
'foo' => '2px',
|
|
|
|
|
'Foo' => '#eeeeee',
|
|
|
|
|
'bar' => 5,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
resourceloader: Don't let module exception break startup
When getScript (or some other method used in a module response)
throws an error, only that module fails (by outputting mw.loader.state
instead of mw.loader.implement). Other modules will work.
This has always been the case and is working fine. For example,
"load.php?modules=foo|bar", where 'foo' throws, will return:
```js
/* exception message: .. */
mw.loader.implement('bar', ..)
mw.loader.state('foo', 'error')
```
The problem, however, is that during the generation of the startup
module, we iterate over all other modules. In 2011, the
getVersionHash method (then: getModifiedTime) was fairly simple
and unlikely to throw errors.
Nowadays, some modules use enableModuleContentVersion which will
involve the same code path as for regular module responses.
The try/catch in ResourceLoader::makeModuleResponse() suffices
for the case of loading modules other than startup. But when
loading the startup module, and an exception happens in getVersionHash,
then the entire startup response is replaced with an exception comment.
Example case:
* A file not existing for a FileModule subclass that uses
enableModuleContentVersion.
* A database error from a data module, like CiteDataModule or
CNChoiceData.
Changes:
* Ensure E-Tag is still useful while an error happens in production
because we respond with 200 OK and one error isn't the same as
another.
Fixed by try/catch in getCombinedVersion.
* Ensure start manifest isn't disrupted by one broken module.
Fixed by try/catch in StartupModule::getModuleRegistrations().
Tests:
* testMakeModuleResponseError: The case that already worked fined.
* testMakeModuleResponseStartupError: The case fixed in this commit.
* testGetCombinedVersion: The case fixed in this commit for E-Tag.
Bug: T152266
Change-Id: Ice4ede5ea594bf3fa591134bc9382bd9c24e2f39
2016-12-03 00:48:14 +00:00
|
|
|
// Clear ResourceLoaderGetConfigVars hooks (called by StartupModule)
|
|
|
|
|
// to avoid notices during testMakeModuleResponse for missing
|
|
|
|
|
// wgResourceLoaderLESSVars keys in extension hooks.
|
|
|
|
|
'wgHooks' => [],
|
2017-02-22 02:51:45 +00:00
|
|
|
'wgShowExceptionDetails' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
Support LESS stylesheets in ResourceLoader
This patch adds support for the LESS stylesheet language to ResourceLoader.
LESS is a stylesheet language that compiles into CSS. The patch includes
lessphp, a LESS compiler implemented in PHP. The rationale for choosing LESS is
explained in a MediaWiki RFC which accompanies this patch, available at
<https://www.mediawiki.org/wiki/Requests_for_comment/LESS>.
LESS support is provided for ResourceLoader file modules. It is triggered by
the presence of the '.less' extension in stylesheet filenames. LESS files are
compiled by lessc, and the resultant CSS is subjected to the standard set of
transformations (CSSJanus & CSSMin). The immediate result of LESS compilation
is encoded as an array, which includes the list of LESS files that were
compiled and their mtimes. This array is cached. Cache invalidation is
performed by comparing the cached mtimes with the mtimes of the files on disk.
If the compiler itself throws an exception, ResourceLoader constructs a
compilation result which consists of the error message encoded as a CSS
comment. Failed compilation results are cached too, but with an expiration time
of five minutes. The expiration time is required because the full list of
referenced files is not known.
Three configuration variables configure the global environment for LESS
modules: $wgResourceLoaderLESSVars, $wgResourceLoaderLESSFunctions, and
$wgResourceLoaderLESSImportPaths. $wgResourceLoaderLESSVars maps variable names
to CSS values, specified as strings. Variables declared in this array are
available in all LESS files. $wgResourceLoaderLESSFunctions is similar, except
it maps custom function names to PHP callables. These functions can be called
from within LESS to transform values. Read more about custom functions at
<http://leafo.net/lessphp/docs/#custom_functions>. Finally,
$wgResourceLoaderLESSImportPaths specifies file system paths in addition to the
current module's path where the LESS compiler should look up files referenced
in @import statements.
The issue of handling of /* @embed */ and /* @noflip */ annotations is left
unresolved. Earlier versions of this patch included an @embed analog
implemented as a LESS custom function, but there was enough ambiguity about
whether the strategy it took was optimal to merit discussing it in a separate,
follow-up patch.
Bug: 40964
Change-Id: Id052a04dd2f76a1f4aef39fbd454bd67f5fd282f
2013-08-11 16:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
/**
|
2016-08-25 01:50:30 +00:00
|
|
|
* Ensure the ResourceLoaderRegisterModules hook is called.
|
|
|
|
|
*
|
2010-12-14 16:26:35 +00:00
|
|
|
* @covers ResourceLoader::__construct
|
|
|
|
|
*/
|
2016-08-25 01:50:30 +00:00
|
|
|
public function testConstructRegistrationHook() {
|
2014-10-15 15:05:04 +00:00
|
|
|
$resourceLoaderRegisterModulesHook = false;
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( 'wgHooks', [
|
|
|
|
|
'ResourceLoaderRegisterModules' => [
|
2014-10-15 15:05:04 +00:00
|
|
|
function ( &$resourceLoader ) use ( &$resourceLoaderRegisterModulesHook ) {
|
|
|
|
|
$resourceLoaderRegisterModulesHook = true;
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
] );
|
2014-10-15 15:05:04 +00:00
|
|
|
|
2016-08-25 01:50:30 +00:00
|
|
|
$unused = new ResourceLoader();
|
2014-10-15 15:05:04 +00:00
|
|
|
$this->assertTrue(
|
|
|
|
|
$resourceLoaderRegisterModulesHook,
|
|
|
|
|
'Hook ResourceLoaderRegisterModules called'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::register
|
|
|
|
|
* @covers ResourceLoader::getModule
|
|
|
|
|
*/
|
2017-04-06 01:19:48 +00:00
|
|
|
public function testRegisterValidObject() {
|
2016-08-25 01:50:30 +00:00
|
|
|
$module = new ResourceLoaderTestModule();
|
|
|
|
|
$resourceLoader = new EmptyResourceLoader();
|
|
|
|
|
$resourceLoader->register( 'test', $module );
|
|
|
|
|
$this->assertEquals( $module, $resourceLoader->getModule( 'test' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
2011-06-07 17:56:40 +00:00
|
|
|
|
2017-04-06 01:19:48 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::register
|
|
|
|
|
* @covers ResourceLoader::getModule
|
|
|
|
|
*/
|
|
|
|
|
public function testRegisterValidArray() {
|
|
|
|
|
$module = new ResourceLoaderTestModule();
|
|
|
|
|
$resourceLoader = new EmptyResourceLoader();
|
|
|
|
|
// Covers case of register() setting $rl->moduleInfos,
|
|
|
|
|
// but $rl->modules lazy-populated by getModule()
|
|
|
|
|
$resourceLoader->register( 'test', [ 'object' => $module ] );
|
|
|
|
|
$this->assertEquals( $module, $resourceLoader->getModule( 'test' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 01:15:04 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::register
|
|
|
|
|
*/
|
|
|
|
|
public function testRegisterEmptyString() {
|
|
|
|
|
$module = new ResourceLoaderTestModule();
|
|
|
|
|
$resourceLoader = new EmptyResourceLoader();
|
|
|
|
|
$resourceLoader->register( '', $module );
|
|
|
|
|
$this->assertEquals( $module, $resourceLoader->getModule( '' ) );
|
|
|
|
|
}
|
|
|
|
|
|
Support LESS stylesheets in ResourceLoader
This patch adds support for the LESS stylesheet language to ResourceLoader.
LESS is a stylesheet language that compiles into CSS. The patch includes
lessphp, a LESS compiler implemented in PHP. The rationale for choosing LESS is
explained in a MediaWiki RFC which accompanies this patch, available at
<https://www.mediawiki.org/wiki/Requests_for_comment/LESS>.
LESS support is provided for ResourceLoader file modules. It is triggered by
the presence of the '.less' extension in stylesheet filenames. LESS files are
compiled by lessc, and the resultant CSS is subjected to the standard set of
transformations (CSSJanus & CSSMin). The immediate result of LESS compilation
is encoded as an array, which includes the list of LESS files that were
compiled and their mtimes. This array is cached. Cache invalidation is
performed by comparing the cached mtimes with the mtimes of the files on disk.
If the compiler itself throws an exception, ResourceLoader constructs a
compilation result which consists of the error message encoded as a CSS
comment. Failed compilation results are cached too, but with an expiration time
of five minutes. The expiration time is required because the full list of
referenced files is not known.
Three configuration variables configure the global environment for LESS
modules: $wgResourceLoaderLESSVars, $wgResourceLoaderLESSFunctions, and
$wgResourceLoaderLESSImportPaths. $wgResourceLoaderLESSVars maps variable names
to CSS values, specified as strings. Variables declared in this array are
available in all LESS files. $wgResourceLoaderLESSFunctions is similar, except
it maps custom function names to PHP callables. These functions can be called
from within LESS to transform values. Read more about custom functions at
<http://leafo.net/lessphp/docs/#custom_functions>. Finally,
$wgResourceLoaderLESSImportPaths specifies file system paths in addition to the
current module's path where the LESS compiler should look up files referenced
in @import statements.
The issue of handling of /* @embed */ and /* @noflip */ annotations is left
unresolved. Earlier versions of this patch included an @embed analog
implemented as a LESS custom function, but there was enough ambiguity about
whether the strategy it took was optimal to merit discussing it in a separate,
follow-up patch.
Bug: 40964
Change-Id: Id052a04dd2f76a1f4aef39fbd454bd67f5fd282f
2013-08-11 16:40:20 +00:00
|
|
|
/**
|
2016-08-25 01:50:30 +00:00
|
|
|
* @covers ResourceLoader::register
|
Support LESS stylesheets in ResourceLoader
This patch adds support for the LESS stylesheet language to ResourceLoader.
LESS is a stylesheet language that compiles into CSS. The patch includes
lessphp, a LESS compiler implemented in PHP. The rationale for choosing LESS is
explained in a MediaWiki RFC which accompanies this patch, available at
<https://www.mediawiki.org/wiki/Requests_for_comment/LESS>.
LESS support is provided for ResourceLoader file modules. It is triggered by
the presence of the '.less' extension in stylesheet filenames. LESS files are
compiled by lessc, and the resultant CSS is subjected to the standard set of
transformations (CSSJanus & CSSMin). The immediate result of LESS compilation
is encoded as an array, which includes the list of LESS files that were
compiled and their mtimes. This array is cached. Cache invalidation is
performed by comparing the cached mtimes with the mtimes of the files on disk.
If the compiler itself throws an exception, ResourceLoader constructs a
compilation result which consists of the error message encoded as a CSS
comment. Failed compilation results are cached too, but with an expiration time
of five minutes. The expiration time is required because the full list of
referenced files is not known.
Three configuration variables configure the global environment for LESS
modules: $wgResourceLoaderLESSVars, $wgResourceLoaderLESSFunctions, and
$wgResourceLoaderLESSImportPaths. $wgResourceLoaderLESSVars maps variable names
to CSS values, specified as strings. Variables declared in this array are
available in all LESS files. $wgResourceLoaderLESSFunctions is similar, except
it maps custom function names to PHP callables. These functions can be called
from within LESS to transform values. Read more about custom functions at
<http://leafo.net/lessphp/docs/#custom_functions>. Finally,
$wgResourceLoaderLESSImportPaths specifies file system paths in addition to the
current module's path where the LESS compiler should look up files referenced
in @import statements.
The issue of handling of /* @embed */ and /* @noflip */ annotations is left
unresolved. Earlier versions of this patch included an @embed analog
implemented as a LESS custom function, but there was enough ambiguity about
whether the strategy it took was optimal to merit discussing it in a separate,
follow-up patch.
Bug: 40964
Change-Id: Id052a04dd2f76a1f4aef39fbd454bd67f5fd282f
2013-08-11 16:40:20 +00:00
|
|
|
*/
|
2016-08-25 01:50:30 +00:00
|
|
|
public function testRegisterInvalidName() {
|
|
|
|
|
$resourceLoader = new EmptyResourceLoader();
|
|
|
|
|
$this->setExpectedException( 'MWException', "name 'test!invalid' is invalid" );
|
|
|
|
|
$resourceLoader->register( 'test!invalid', new ResourceLoaderTestModule() );
|
Support LESS stylesheets in ResourceLoader
This patch adds support for the LESS stylesheet language to ResourceLoader.
LESS is a stylesheet language that compiles into CSS. The patch includes
lessphp, a LESS compiler implemented in PHP. The rationale for choosing LESS is
explained in a MediaWiki RFC which accompanies this patch, available at
<https://www.mediawiki.org/wiki/Requests_for_comment/LESS>.
LESS support is provided for ResourceLoader file modules. It is triggered by
the presence of the '.less' extension in stylesheet filenames. LESS files are
compiled by lessc, and the resultant CSS is subjected to the standard set of
transformations (CSSJanus & CSSMin). The immediate result of LESS compilation
is encoded as an array, which includes the list of LESS files that were
compiled and their mtimes. This array is cached. Cache invalidation is
performed by comparing the cached mtimes with the mtimes of the files on disk.
If the compiler itself throws an exception, ResourceLoader constructs a
compilation result which consists of the error message encoded as a CSS
comment. Failed compilation results are cached too, but with an expiration time
of five minutes. The expiration time is required because the full list of
referenced files is not known.
Three configuration variables configure the global environment for LESS
modules: $wgResourceLoaderLESSVars, $wgResourceLoaderLESSFunctions, and
$wgResourceLoaderLESSImportPaths. $wgResourceLoaderLESSVars maps variable names
to CSS values, specified as strings. Variables declared in this array are
available in all LESS files. $wgResourceLoaderLESSFunctions is similar, except
it maps custom function names to PHP callables. These functions can be called
from within LESS to transform values. Read more about custom functions at
<http://leafo.net/lessphp/docs/#custom_functions>. Finally,
$wgResourceLoaderLESSImportPaths specifies file system paths in addition to the
current module's path where the LESS compiler should look up files referenced
in @import statements.
The issue of handling of /* @embed */ and /* @noflip */ annotations is left
unresolved. Earlier versions of this patch included an @embed analog
implemented as a LESS custom function, but there was enough ambiguity about
whether the strategy it took was optimal to merit discussing it in a separate,
follow-up patch.
Bug: 40964
Change-Id: Id052a04dd2f76a1f4aef39fbd454bd67f5fd282f
2013-08-11 16:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-20 21:26:13 +00:00
|
|
|
/**
|
2016-08-25 01:50:30 +00:00
|
|
|
* @covers ResourceLoader::register
|
2014-09-20 21:26:13 +00:00
|
|
|
*/
|
2016-08-25 01:50:30 +00:00
|
|
|
public function testRegisterInvalidType() {
|
|
|
|
|
$resourceLoader = new EmptyResourceLoader();
|
|
|
|
|
$this->setExpectedException( 'MWException', 'ResourceLoader module info type error' );
|
|
|
|
|
$resourceLoader->register( 'test', new stdClass() );
|
2014-09-20 21:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-07 17:56:40 +00:00
|
|
|
/**
|
2016-08-25 01:50:30 +00:00
|
|
|
* @covers ResourceLoader::getModuleNames
|
2011-06-07 17:56:40 +00:00
|
|
|
*/
|
2016-08-25 01:50:30 +00:00
|
|
|
public function testGetModuleNames() {
|
|
|
|
|
// Use an empty one so that core and extension modules don't get in.
|
|
|
|
|
$resourceLoader = new EmptyResourceLoader();
|
|
|
|
|
$resourceLoader->register( 'test.foo', new ResourceLoaderTestModule() );
|
|
|
|
|
$resourceLoader->register( 'test.bar', new ResourceLoaderTestModule() );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ 'test.foo', 'test.bar' ],
|
|
|
|
|
$resourceLoader->getModuleNames()
|
|
|
|
|
);
|
2011-06-07 17:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-08-25 01:50:30 +00:00
|
|
|
* @covers ResourceLoader::isModuleRegistered
|
2011-06-07 17:56:40 +00:00
|
|
|
*/
|
2016-08-25 01:50:30 +00:00
|
|
|
public function testIsModuleRegistered() {
|
|
|
|
|
$rl = new EmptyResourceLoader();
|
|
|
|
|
$rl->register( 'test', new ResourceLoaderTestModule() );
|
|
|
|
|
$this->assertTrue( $rl->isModuleRegistered( 'test' ) );
|
|
|
|
|
$this->assertFalse( $rl->isModuleRegistered( 'test.unknown' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::getModule
|
|
|
|
|
*/
|
|
|
|
|
public function testGetModuleUnknown() {
|
|
|
|
|
$rl = new EmptyResourceLoader();
|
|
|
|
|
$this->assertSame( null, $rl->getModule( 'test' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::getModule
|
|
|
|
|
*/
|
|
|
|
|
public function testGetModuleClass() {
|
|
|
|
|
$rl = new EmptyResourceLoader();
|
|
|
|
|
$rl->register( 'test', [ 'class' => ResourceLoaderTestModule::class ] );
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
ResourceLoaderTestModule::class,
|
|
|
|
|
$rl->getModule( 'test' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::getModule
|
|
|
|
|
*/
|
|
|
|
|
public function testGetModuleClassDefault() {
|
|
|
|
|
$rl = new EmptyResourceLoader();
|
|
|
|
|
$rl->register( 'test', [] );
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
ResourceLoaderFileModule::class,
|
|
|
|
|
$rl->getModule( 'test' ),
|
|
|
|
|
'Array-style module registrations default to FileModule'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderFileModule::compileLessFile
|
|
|
|
|
*/
|
|
|
|
|
public function testLessFileCompilation() {
|
|
|
|
|
$context = $this->getResourceLoaderContext();
|
|
|
|
|
$basePath = __DIR__ . '/../../data/less/module';
|
|
|
|
|
$module = new ResourceLoaderFileModule( [
|
|
|
|
|
'localBasePath' => $basePath,
|
|
|
|
|
'styles' => [ 'styles.less' ],
|
|
|
|
|
] );
|
|
|
|
|
$module->setName( 'test.less' );
|
|
|
|
|
$styles = $module->getStyles( $context );
|
|
|
|
|
$this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
|
2011-06-07 17:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function providePackedModules() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2011-06-07 17:56:40 +00:00
|
|
|
'Example from makePackedModulesString doc comment',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ],
|
2011-06-07 17:56:40 +00:00
|
|
|
'foo.bar,baz|bar.baz,quux',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2011-06-07 17:56:40 +00:00
|
|
|
'Example from expandModuleNames doc comment',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'jquery.foo', 'jquery.bar', 'jquery.ui.baz', 'jquery.ui.quux' ],
|
2011-06-07 17:56:40 +00:00
|
|
|
'jquery.foo,bar|jquery.ui.baz,quux',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2011-06-07 17:56:40 +00:00
|
|
|
'Regression fixed in r88706 with dotless names',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo', 'bar', 'baz' ],
|
2011-06-07 17:56:40 +00:00
|
|
|
'foo,bar,baz',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-05-27 15:13:59 +00:00
|
|
|
'Prefixless modules after a prefixed module',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'single.module', 'foobar', 'foobaz' ],
|
2013-05-27 15:13:59 +00:00
|
|
|
'single.module|foobar,foobaz',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-08-29 23:35:55 +00:00
|
|
|
[
|
|
|
|
|
'Ordering',
|
|
|
|
|
[ 'foo', 'foo.baz', 'baz.quux', 'foo.bar' ],
|
|
|
|
|
'foo|foo.baz,bar|baz.quux',
|
|
|
|
|
[ 'foo', 'foo.baz', 'foo.bar', 'baz.quux' ],
|
|
|
|
|
]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-06-07 17:56:40 +00:00
|
|
|
}
|
2014-06-28 02:57:40 +00:00
|
|
|
|
2016-08-25 01:50:30 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider providePackedModules
|
|
|
|
|
* @covers ResourceLoader::makePackedModulesString
|
|
|
|
|
*/
|
|
|
|
|
public function testMakePackedModulesString( $desc, $modules, $packed ) {
|
|
|
|
|
$this->assertEquals( $packed, ResourceLoader::makePackedModulesString( $modules ), $desc );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider providePackedModules
|
|
|
|
|
* @covers ResourceLoaderContext::expandModuleNames
|
|
|
|
|
*/
|
2016-08-29 23:35:55 +00:00
|
|
|
public function testExpandModuleNames( $desc, $modules, $packed, $unpacked = null ) {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$unpacked ?: $modules,
|
|
|
|
|
ResourceLoaderContext::expandModuleNames( $packed ),
|
|
|
|
|
$desc
|
|
|
|
|
);
|
2016-08-25 01:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 08:02:48 +00:00
|
|
|
public static function provideAddSource() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2016-08-25 01:50:30 +00:00
|
|
|
[ 'foowiki', 'https://example.org/w/load.php', 'foowiki' ],
|
|
|
|
|
[ 'foowiki', [ 'loadScript' => 'https://example.org/w/load.php' ], 'foowiki' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2016-08-25 01:50:30 +00:00
|
|
|
[
|
|
|
|
|
'foowiki' => 'https://example.org/w/load.php',
|
|
|
|
|
'bazwiki' => 'https://example.com/w/load.php',
|
|
|
|
|
],
|
2014-08-25 08:02:48 +00:00
|
|
|
null,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foowiki', 'bazwiki' ]
|
2016-08-25 01:50:30 +00:00
|
|
|
]
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-08-25 08:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideAddSource
|
|
|
|
|
* @covers ResourceLoader::addSource
|
2015-03-23 03:57:45 +00:00
|
|
|
* @covers ResourceLoader::getSources
|
2014-08-25 08:02:48 +00:00
|
|
|
*/
|
|
|
|
|
public function testAddSource( $name, $info, $expected ) {
|
|
|
|
|
$rl = new ResourceLoader;
|
|
|
|
|
$rl->addSource( $name, $info );
|
|
|
|
|
if ( is_array( $expected ) ) {
|
|
|
|
|
foreach ( $expected as $source ) {
|
|
|
|
|
$this->assertArrayHasKey( $source, $rl->getSources() );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertArrayHasKey( $expected, $rl->getSources() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:50:30 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::addSource
|
|
|
|
|
*/
|
|
|
|
|
public function testAddSourceDupe() {
|
|
|
|
|
$rl = new ResourceLoader;
|
|
|
|
|
$this->setExpectedException( 'MWException', 'ResourceLoader duplicate source addition error' );
|
|
|
|
|
$rl->addSource( 'foo', 'https://example.org/w/load.php' );
|
|
|
|
|
$rl->addSource( 'foo', 'https://example.com/w/load.php' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::addSource
|
|
|
|
|
*/
|
|
|
|
|
public function testAddSourceInvalid() {
|
|
|
|
|
$rl = new ResourceLoader;
|
|
|
|
|
$this->setExpectedException( 'MWException', 'with no "loadScript" key' );
|
|
|
|
|
$rl->addSource( 'foo', [ 'x' => 'https://example.org/w/load.php' ] );
|
2014-06-28 02:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-09 01:17:53 +00:00
|
|
|
public static function provideLoaderImplement() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ [
|
2014-12-09 01:17:53 +00:00
|
|
|
'title' => 'Implement scripts, styles and messages',
|
|
|
|
|
|
|
|
|
|
'name' => 'test.example',
|
|
|
|
|
'scripts' => 'mw.example();',
|
2016-02-17 09:09:32 +00:00
|
|
|
'styles' => [ 'css' => [ '.mw-example {}' ] ],
|
|
|
|
|
'messages' => [ 'example' => '' ],
|
|
|
|
|
'templates' => [],
|
2014-12-09 01:17:53 +00:00
|
|
|
|
2016-01-22 19:29:28 +00:00
|
|
|
'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
|
2014-12-09 01:17:53 +00:00
|
|
|
mw.example();
|
|
|
|
|
}, {
|
|
|
|
|
"css": [
|
|
|
|
|
".mw-example {}"
|
|
|
|
|
]
|
|
|
|
|
}, {
|
|
|
|
|
"example": ""
|
|
|
|
|
} );',
|
2016-02-17 09:09:32 +00:00
|
|
|
] ],
|
|
|
|
|
[ [
|
2014-12-09 01:17:53 +00:00
|
|
|
'title' => 'Implement scripts',
|
|
|
|
|
|
|
|
|
|
'name' => 'test.example',
|
|
|
|
|
'scripts' => 'mw.example();',
|
2016-02-17 09:09:32 +00:00
|
|
|
'styles' => [],
|
2014-12-09 01:17:53 +00:00
|
|
|
|
2016-01-22 19:29:28 +00:00
|
|
|
'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
|
2014-12-09 01:17:53 +00:00
|
|
|
mw.example();
|
|
|
|
|
} );',
|
2016-02-17 09:09:32 +00:00
|
|
|
] ],
|
|
|
|
|
[ [
|
2014-12-09 01:17:53 +00:00
|
|
|
'title' => 'Implement styles',
|
|
|
|
|
|
|
|
|
|
'name' => 'test.example',
|
2016-02-17 09:09:32 +00:00
|
|
|
'scripts' => [],
|
|
|
|
|
'styles' => [ 'css' => [ '.mw-example {}' ] ],
|
2014-12-09 01:17:53 +00:00
|
|
|
|
|
|
|
|
'expected' => 'mw.loader.implement( "test.example", [], {
|
|
|
|
|
"css": [
|
|
|
|
|
".mw-example {}"
|
|
|
|
|
]
|
|
|
|
|
} );',
|
2016-02-17 09:09:32 +00:00
|
|
|
] ],
|
|
|
|
|
[ [
|
2014-12-09 01:17:53 +00:00
|
|
|
'title' => 'Implement scripts and messages',
|
|
|
|
|
|
|
|
|
|
'name' => 'test.example',
|
|
|
|
|
'scripts' => 'mw.example();',
|
2016-02-17 09:09:32 +00:00
|
|
|
'messages' => [ 'example' => '' ],
|
2014-12-09 01:17:53 +00:00
|
|
|
|
2016-01-22 19:29:28 +00:00
|
|
|
'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
|
2014-12-09 01:17:53 +00:00
|
|
|
mw.example();
|
|
|
|
|
}, {}, {
|
|
|
|
|
"example": ""
|
|
|
|
|
} );',
|
2016-02-17 09:09:32 +00:00
|
|
|
] ],
|
|
|
|
|
[ [
|
2014-12-09 01:17:53 +00:00
|
|
|
'title' => 'Implement scripts and templates',
|
|
|
|
|
|
|
|
|
|
'name' => 'test.example',
|
|
|
|
|
'scripts' => 'mw.example();',
|
2016-02-17 09:09:32 +00:00
|
|
|
'templates' => [ 'example.html' => '' ],
|
2014-12-09 01:17:53 +00:00
|
|
|
|
2016-01-22 19:29:28 +00:00
|
|
|
'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery, require, module ) {
|
2014-12-09 01:17:53 +00:00
|
|
|
mw.example();
|
|
|
|
|
}, {}, {}, {
|
|
|
|
|
"example.html": ""
|
|
|
|
|
} );',
|
2016-02-17 09:09:32 +00:00
|
|
|
] ],
|
2016-08-25 01:50:30 +00:00
|
|
|
[ [
|
|
|
|
|
'title' => 'Implement unwrapped user script',
|
|
|
|
|
|
|
|
|
|
'name' => 'user',
|
|
|
|
|
'scripts' => 'mw.example( 1 );',
|
2016-09-15 04:01:09 +00:00
|
|
|
'wrap' => false,
|
2016-08-25 01:50:30 +00:00
|
|
|
|
|
|
|
|
'expected' => 'mw.loader.implement( "user", "mw.example( 1 );" );',
|
|
|
|
|
] ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-12-09 01:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideLoaderImplement
|
|
|
|
|
* @covers ResourceLoader::makeLoaderImplementScript
|
2016-08-25 01:50:30 +00:00
|
|
|
* @covers ResourceLoader::trimArray
|
2014-12-09 01:17:53 +00:00
|
|
|
*/
|
|
|
|
|
public function testMakeLoaderImplementScript( $case ) {
|
2016-08-25 01:50:30 +00:00
|
|
|
$case += [
|
2016-09-15 04:01:09 +00:00
|
|
|
'wrap' => true,
|
|
|
|
|
'styles' => [], 'templates' => [], 'messages' => new XmlJsCode( '{}' )
|
2016-08-25 01:50:30 +00:00
|
|
|
];
|
|
|
|
|
ResourceLoader::clearCache();
|
2016-09-15 04:01:09 +00:00
|
|
|
$this->setMwGlobals( 'wgResourceLoaderDebug', true );
|
2016-08-25 01:50:30 +00:00
|
|
|
|
2016-09-15 04:01:09 +00:00
|
|
|
$rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' );
|
2014-12-09 01:17:53 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$case['expected'],
|
2016-09-15 04:01:09 +00:00
|
|
|
$rl->makeLoaderImplementScript(
|
2014-12-09 01:17:53 +00:00
|
|
|
$case['name'],
|
2016-09-15 04:01:09 +00:00
|
|
|
( $case['wrap'] && is_string( $case['scripts'] ) )
|
|
|
|
|
? new XmlJsCode( $case['scripts'] )
|
|
|
|
|
: $case['scripts'],
|
2014-12-09 01:17:53 +00:00
|
|
|
$case['styles'],
|
|
|
|
|
$case['messages'],
|
|
|
|
|
$case['templates']
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:50:30 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::makeLoaderImplementScript
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeLoaderImplementScriptInvalid() {
|
|
|
|
|
$this->setExpectedException( 'MWException', 'Invalid scripts error' );
|
2016-09-15 04:01:09 +00:00
|
|
|
$rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' );
|
|
|
|
|
$rl->makeLoaderImplementScript(
|
2016-08-25 01:50:30 +00:00
|
|
|
'test', // name
|
|
|
|
|
123, // scripts
|
|
|
|
|
null, // styles
|
|
|
|
|
null, // messages
|
|
|
|
|
null // templates
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 01:19:48 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::makeLoaderRegisterScript
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeLoaderRegisterScript() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mw.loader.register( [
|
|
|
|
|
[
|
|
|
|
|
"test.name",
|
|
|
|
|
"1234567"
|
|
|
|
|
]
|
|
|
|
|
] );',
|
|
|
|
|
ResourceLoader::makeLoaderRegisterScript( [
|
|
|
|
|
[ 'test.name', '1234567' ],
|
|
|
|
|
] ),
|
|
|
|
|
'Nested array parameter'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mw.loader.register( "test.name", "1234567" );',
|
|
|
|
|
ResourceLoader::makeLoaderRegisterScript(
|
|
|
|
|
'test.name',
|
|
|
|
|
'1234567'
|
|
|
|
|
),
|
|
|
|
|
'Variadic parameters'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 01:50:30 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::makeLoaderSourcesScript
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeLoaderSourcesScript() {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mw.loader.addSource( "local", "/w/load.php" );',
|
|
|
|
|
ResourceLoader::makeLoaderSourcesScript( 'local', '/w/load.php' )
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mw.loader.addSource( {
|
|
|
|
|
"local": "/w/load.php"
|
|
|
|
|
} );',
|
|
|
|
|
ResourceLoader::makeLoaderSourcesScript( [ 'local' => '/w/load.php' ] )
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mw.loader.addSource( {
|
|
|
|
|
"local": "/w/load.php",
|
|
|
|
|
"example": "https://example.org/w/load.php"
|
|
|
|
|
} );',
|
|
|
|
|
ResourceLoader::makeLoaderSourcesScript( [
|
|
|
|
|
'local' => '/w/load.php',
|
|
|
|
|
'example' => 'https://example.org/w/load.php'
|
|
|
|
|
] )
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'mw.loader.addSource( [] );',
|
|
|
|
|
ResourceLoader::makeLoaderSourcesScript( [] )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static function fakeSources() {
|
|
|
|
|
return [
|
|
|
|
|
'examplewiki' => [
|
|
|
|
|
'loadScript' => '//example.org/w/load.php',
|
|
|
|
|
'apiScript' => '//example.org/w/api.php',
|
|
|
|
|
],
|
|
|
|
|
'example2wiki' => [
|
|
|
|
|
'loadScript' => '//example.com/w/load.php',
|
|
|
|
|
'apiScript' => '//example.com/w/api.php',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-28 02:57:40 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::getLoadScript
|
|
|
|
|
*/
|
|
|
|
|
public function testGetLoadScript() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( 'wgResourceLoaderSources', [] );
|
2014-06-28 02:57:40 +00:00
|
|
|
$rl = new ResourceLoader();
|
|
|
|
|
$sources = self::fakeSources();
|
|
|
|
|
$rl->addSource( $sources );
|
2016-02-17 09:09:32 +00:00
|
|
|
foreach ( [ 'examplewiki', 'example2wiki' ] as $name ) {
|
2014-06-28 02:57:40 +00:00
|
|
|
$this->assertEquals( $rl->getLoadScript( $name ), $sources[$name]['loadScript'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$rl->getLoadScript( 'thiswasneverreigstered' );
|
|
|
|
|
$this->assertTrue( false, 'ResourceLoader::getLoadScript should have thrown an exception' );
|
|
|
|
|
} catch ( MWException $e ) {
|
|
|
|
|
$this->assertTrue( true );
|
|
|
|
|
}
|
|
|
|
|
}
|
resourceloader: Don't let module exception break startup
When getScript (or some other method used in a module response)
throws an error, only that module fails (by outputting mw.loader.state
instead of mw.loader.implement). Other modules will work.
This has always been the case and is working fine. For example,
"load.php?modules=foo|bar", where 'foo' throws, will return:
```js
/* exception message: .. */
mw.loader.implement('bar', ..)
mw.loader.state('foo', 'error')
```
The problem, however, is that during the generation of the startup
module, we iterate over all other modules. In 2011, the
getVersionHash method (then: getModifiedTime) was fairly simple
and unlikely to throw errors.
Nowadays, some modules use enableModuleContentVersion which will
involve the same code path as for regular module responses.
The try/catch in ResourceLoader::makeModuleResponse() suffices
for the case of loading modules other than startup. But when
loading the startup module, and an exception happens in getVersionHash,
then the entire startup response is replaced with an exception comment.
Example case:
* A file not existing for a FileModule subclass that uses
enableModuleContentVersion.
* A database error from a data module, like CiteDataModule or
CNChoiceData.
Changes:
* Ensure E-Tag is still useful while an error happens in production
because we respond with 200 OK and one error isn't the same as
another.
Fixed by try/catch in getCombinedVersion.
* Ensure start manifest isn't disrupted by one broken module.
Fixed by try/catch in StartupModule::getModuleRegistrations().
Tests:
* testMakeModuleResponseError: The case that already worked fined.
* testMakeModuleResponseStartupError: The case fixed in this commit.
* testGetCombinedVersion: The case fixed in this commit for E-Tag.
Bug: T152266
Change-Id: Ice4ede5ea594bf3fa591134bc9382bd9c24e2f39
2016-12-03 00:48:14 +00:00
|
|
|
|
|
|
|
|
protected function getFailFerryMock() {
|
|
|
|
|
$mock = $this->getMockBuilder( ResourceLoaderTestModule::class )
|
|
|
|
|
->setMethods( [ 'getScript' ] )
|
|
|
|
|
->getMock();
|
|
|
|
|
$mock->method( 'getScript' )->will( $this->throwException(
|
|
|
|
|
new Exception( 'Ferry not found' )
|
|
|
|
|
) );
|
|
|
|
|
return $mock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getSimpleModuleMock( $script = '' ) {
|
|
|
|
|
$mock = $this->getMockBuilder( ResourceLoaderTestModule::class )
|
|
|
|
|
->setMethods( [ 'getScript' ] )
|
|
|
|
|
->getMock();
|
|
|
|
|
$mock->method( 'getScript' )->willReturn( $script );
|
|
|
|
|
return $mock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoader::getCombinedVersion
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCombinedVersion() {
|
|
|
|
|
$rl = new EmptyResourceLoader();
|
|
|
|
|
$rl->register( [
|
|
|
|
|
'foo' => self::getSimpleModuleMock(),
|
|
|
|
|
'ferry' => self::getFailFerryMock(),
|
|
|
|
|
'bar' => self::getSimpleModuleMock(),
|
|
|
|
|
] );
|
|
|
|
|
$context = $this->getResourceLoaderContext( [], $rl );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
ResourceLoader::makeHash( self::BLANK_VERSION ),
|
|
|
|
|
$rl->getCombinedVersion( $context, [ 'foo' ] ),
|
|
|
|
|
'compute foo'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Verify that getCombinedVersion() does not throw when ferry fails.
|
|
|
|
|
// Instead it gracefully continues to combine the remaining modules.
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
ResourceLoader::makeHash( self::BLANK_VERSION . self::BLANK_VERSION ),
|
|
|
|
|
$rl->getCombinedVersion( $context, [ 'foo', 'ferry', 'bar' ] ),
|
|
|
|
|
'compute foo+ferry+bar (T152266)'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify that when building module content in a load.php response,
|
|
|
|
|
* an exception from one module will not break script output from
|
|
|
|
|
* other modules.
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeModuleResponseError() {
|
|
|
|
|
$modules = [
|
|
|
|
|
'foo' => self::getSimpleModuleMock( 'foo();' ),
|
|
|
|
|
'ferry' => self::getFailFerryMock(),
|
|
|
|
|
'bar' => self::getSimpleModuleMock( 'bar();' ),
|
|
|
|
|
];
|
|
|
|
|
$rl = new EmptyResourceLoader();
|
|
|
|
|
$rl->register( $modules );
|
|
|
|
|
$context = $this->getResourceLoaderContext(
|
|
|
|
|
[
|
|
|
|
|
'modules' => 'foo|ferry|bar',
|
|
|
|
|
'only' => 'scripts',
|
|
|
|
|
],
|
|
|
|
|
$rl
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$response = $rl->makeModuleResponse( $context, $modules );
|
|
|
|
|
$errors = $rl->getErrors();
|
|
|
|
|
|
|
|
|
|
$this->assertCount( 1, $errors );
|
|
|
|
|
$this->assertRegExp( '/Ferry not found/', $errors[0] );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'foo();bar();mw.loader.state( {
|
|
|
|
|
"ferry": "error",
|
|
|
|
|
"foo": "ready",
|
|
|
|
|
"bar": "ready"
|
|
|
|
|
} );',
|
|
|
|
|
$response
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify that when building the startup module response,
|
|
|
|
|
* an exception from one module class will not break the entire
|
|
|
|
|
* startup module response. See T152266.
|
|
|
|
|
*/
|
|
|
|
|
public function testMakeModuleResponseStartupError() {
|
|
|
|
|
$rl = new EmptyResourceLoader();
|
|
|
|
|
$rl->register( [
|
|
|
|
|
'foo' => self::getSimpleModuleMock( 'foo();' ),
|
|
|
|
|
'ferry' => self::getFailFerryMock(),
|
|
|
|
|
'bar' => self::getSimpleModuleMock( 'bar();' ),
|
|
|
|
|
'startup' => [ 'class' => 'ResourceLoaderStartUpModule' ],
|
|
|
|
|
] );
|
|
|
|
|
$context = $this->getResourceLoaderContext(
|
|
|
|
|
[
|
|
|
|
|
'modules' => 'startup',
|
|
|
|
|
'only' => 'scripts',
|
|
|
|
|
],
|
|
|
|
|
$rl
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
[ 'foo', 'ferry', 'bar', 'startup' ],
|
|
|
|
|
$rl->getModuleNames(),
|
|
|
|
|
'getModuleNames'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$modules = [ 'startup' => $rl->getModule( 'startup' ) ];
|
|
|
|
|
$response = $rl->makeModuleResponse( $context, $modules );
|
|
|
|
|
$errors = $rl->getErrors();
|
|
|
|
|
|
|
|
|
|
$this->assertRegExp( '/Ferry not found/', $errors[0] );
|
|
|
|
|
$this->assertCount( 1, $errors );
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/isCompatible.*function startUp/s',
|
|
|
|
|
$response,
|
|
|
|
|
'startup response undisrupted (T152266)'
|
|
|
|
|
);
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/register\([^)]+"ferry",\s*""/s',
|
|
|
|
|
$response,
|
|
|
|
|
'startup response registers broken module'
|
|
|
|
|
);
|
|
|
|
|
$this->assertRegExp(
|
|
|
|
|
'/state\([^)]+"ferry":\s*"error"/s',
|
|
|
|
|
$response,
|
|
|
|
|
'startup response sets state to error'
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|