Merge "resourceloader: Preserve new 'debug' param in getScriptURLsForDebug()"
This commit is contained in:
commit
3801581dae
3 changed files with 69 additions and 7 deletions
|
|
@ -295,7 +295,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
|
||||||
* This function must only be called when:
|
* This function must only be called when:
|
||||||
*
|
*
|
||||||
* 1. We're in debug mode,
|
* 1. We're in debug mode,
|
||||||
* 2. there is no `only=` parameter and,
|
* 2. There is no `only=` parameter and,
|
||||||
* 3. self::supportsURLLoading() returns true.
|
* 3. self::supportsURLLoading() returns true.
|
||||||
*
|
*
|
||||||
* Point 2 is prevents an infinite loop, therefore this function
|
* Point 2 is prevents an infinite loop, therefore this function
|
||||||
|
|
@ -310,7 +310,6 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
|
||||||
$derivative = new DerivativeResourceLoaderContext( $context );
|
$derivative = new DerivativeResourceLoaderContext( $context );
|
||||||
$derivative->setModules( [ $this->getName() ] );
|
$derivative->setModules( [ $this->getName() ] );
|
||||||
$derivative->setOnly( 'scripts' );
|
$derivative->setOnly( 'scripts' );
|
||||||
$derivative->setDebug( true );
|
|
||||||
|
|
||||||
$url = $rl->createLoaderURL(
|
$url = $rl->createLoaderURL(
|
||||||
$this->getSource(),
|
$this->getSource(),
|
||||||
|
|
@ -353,7 +352,15 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
|
||||||
* Get the URL or URLs to load for this module's CSS in debug mode.
|
* Get the URL or URLs to load for this module's CSS in debug mode.
|
||||||
* The default behavior is to return a load.php?only=styles URL for
|
* The default behavior is to return a load.php?only=styles URL for
|
||||||
* the module, but file-based modules will want to override this to
|
* the module, but file-based modules will want to override this to
|
||||||
* load the files directly. See also getScriptURLsForDebug()
|
* load the files directly
|
||||||
|
*
|
||||||
|
* This function must only be called when:
|
||||||
|
*
|
||||||
|
* 1. We're in debug mode,
|
||||||
|
* 2. There is no `only=` parameter and,
|
||||||
|
* 3. self::supportsURLLoading() returns true.
|
||||||
|
*
|
||||||
|
* See also getScriptURLsForDebug().
|
||||||
*
|
*
|
||||||
* @stable to override
|
* @stable to override
|
||||||
* @param ResourceLoaderContext $context
|
* @param ResourceLoaderContext $context
|
||||||
|
|
@ -364,7 +371,6 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
|
||||||
$derivative = new DerivativeResourceLoaderContext( $context );
|
$derivative = new DerivativeResourceLoaderContext( $context );
|
||||||
$derivative->setModules( [ $this->getName() ] );
|
$derivative->setModules( [ $this->getName() ] );
|
||||||
$derivative->setOnly( 'styles' );
|
$derivative->setOnly( 'styles' );
|
||||||
$derivative->setDebug( true );
|
|
||||||
|
|
||||||
$url = $resourceLoader->createLoaderURL(
|
$url = $resourceLoader->createLoaderURL(
|
||||||
$this->getSource(),
|
$this->getSource(),
|
||||||
|
|
|
||||||
|
|
@ -181,14 +181,17 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ResourceLoader::expandUrl
|
|
||||||
* @covers ResourceLoaderFileModule
|
* @covers ResourceLoaderFileModule
|
||||||
|
* @covers ResourceLoaderModule
|
||||||
|
* @covers ResourceLoader::createLoaderURL
|
||||||
|
* @covers ResourceLoader::expandUrl
|
||||||
*/
|
*/
|
||||||
public function testGetScriptURLsForDebug() {
|
public function testGetURLsForDebug() {
|
||||||
$ctx = $this->getResourceLoaderContext();
|
$ctx = $this->getResourceLoaderContext();
|
||||||
$module = new ResourceLoaderFileModule( [
|
$module = new ResourceLoaderFileModule( [
|
||||||
'localBasePath' => __DIR__ . '/../../data/resourceloader',
|
'localBasePath' => __DIR__ . '/../../data/resourceloader',
|
||||||
'remoteBasePath' => '/w/something',
|
'remoteBasePath' => '/w/something',
|
||||||
|
'styles' => [ 'simple.css' ],
|
||||||
'scripts' => [ 'script-comment.js' ],
|
'scripts' => [ 'script-comment.js' ],
|
||||||
] );
|
] );
|
||||||
$module->setName( 'testing' );
|
$module->setName( 'testing' );
|
||||||
|
|
@ -198,7 +201,15 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
|
||||||
[
|
[
|
||||||
'https://example.org/w/something/script-comment.js'
|
'https://example.org/w/something/script-comment.js'
|
||||||
],
|
],
|
||||||
$module->getScriptURLsForDebug( $ctx )
|
$module->getScriptURLsForDebug( $ctx ),
|
||||||
|
'script urls'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[ 'all' => [
|
||||||
|
'/w/something/simple.css'
|
||||||
|
] ],
|
||||||
|
$module->getStyleURLsForDebug( $ctx ),
|
||||||
|
'style urls'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,51 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
|
||||||
$module->getVersionHash( $context );
|
$module->getVersionHash( $context );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ResourceLoaderModule::getScriptURLsForDebug
|
||||||
|
* @covers ResourceLoader
|
||||||
|
* @covers ResourceLoaderModule::getScriptURLsForDebug
|
||||||
|
*/
|
||||||
|
public function testGetURLsForDebug() {
|
||||||
|
$module = new ResourceLoaderTestModule( [
|
||||||
|
'script' => 'foo();',
|
||||||
|
'styles' => '.foo { color: blue; }',
|
||||||
|
] );
|
||||||
|
$context = $this->getResourceLoaderContext( [ 'debug' => 'true' ] );
|
||||||
|
$module->setConfig( $context->getResourceLoader()->getConfig() );
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'https://example.org/w/load.php?debug=1&lang=en&modules=&only=scripts'
|
||||||
|
],
|
||||||
|
$module->getScriptURLsForDebug( $context ),
|
||||||
|
'script urls debug=true'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[ 'all' => [
|
||||||
|
'/w/load.php?debug=1&lang=en&modules=&only=styles'
|
||||||
|
] ],
|
||||||
|
$module->getStyleURLsForDebug( $context ),
|
||||||
|
'style urls debug=true'
|
||||||
|
);
|
||||||
|
|
||||||
|
$context = $this->getResourceLoaderContext( [ 'debug' => '2' ] );
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
'https://example.org/w/load.php?debug=2&lang=en&modules=&only=scripts'
|
||||||
|
],
|
||||||
|
$module->getScriptURLsForDebug( $context ),
|
||||||
|
'script urls debug=2'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
[ 'all' => [
|
||||||
|
'/w/load.php?debug=2&lang=en&modules=&only=styles'
|
||||||
|
] ],
|
||||||
|
$module->getStyleURLsForDebug( $context ),
|
||||||
|
'style urls debug=2'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ResourceLoaderModule::validateScriptFile
|
* @covers ResourceLoaderModule::validateScriptFile
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue