aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2021-08-25 03:36:25 +0100
committerKrinkle <krinklemail@gmail.com>2021-08-25 20:05:38 +0000
commitb99458ceabaf26f9ff0614b538364d06ec99d09a (patch)
treec98d8979874ca88dec3015e694bc3bdfeab45e57 /tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
parent89259d5a617e3e2a30c4546e8e4725af3c5b206b (diff)
downloadmediawikicore-b99458ceabaf26f9ff0614b538364d06ec99d09a.tar.gz
mediawikicore-b99458ceabaf26f9ff0614b538364d06ec99d09a.zip
resourceloader: Fix debug mode for RL-to-RL cross-wiki module loads
The native "foreign module source" feature, as used by the GlobalCssJs extension, did not work correctly in debug mode as the urls returned by the remote wiki were formatted as "/w/load.php...", which would be interpreted by the browser relative to the host document, instead of relative to the parent script. For example: 1. Page view on en.wikipedia.org. 2. Script call to meta.wikimedia.org/w/load.php?debug=true&modules=ext.globalCssJs.user&user This URL is formatted by getScriptURLsForDebug on en.wikipedia.org, when building the article HTML. It knows the modules is on Meta, and formats it as such. So far so good. 3. meta.wikimedia.org responds with an array of urls for sub resources. That array contained URLs like "/w/load.php...only=scripts". These were formatted by getScriptURLsForDebug running on Meta, no longer with a reason to make it a Meta-Wiki URL as it isn't perceived as cross-wiki. It is indistinguishable from debugging a Meta-Wiki page view from its perspective. This patch affects scenario 3 by always expanding it relative to the current-request's wgServer. We still only do this in debug mode. There is not yet a need to do this in non-debug mode, and if there was we'd likely want to find a way to avoid it in the common case to keep embedded URLs short. The ResourceLoader::expandUrl() method is similar to the one in Wikimedia\Minify\CSSMin. Test Plan: * view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=site For Module base class. Before, the array entries were relative. After, they are full. * view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=jquery For FileModule. Before, the array entries were relative. After, they are full. * view-source:http://mw.localhost:8080/wiki/Main_Page?debug=true Unchanged. * view-source:http://mw.localhost:8080/wiki/Main_Page Unchanged. Bug: T255367 Change-Id: I83919744b2677c7fb52b84089ecc60b89957d32a
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
index bc01ce49053f..7959742b10cc 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
@@ -168,6 +168,28 @@ class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
}
/**
+ * @covers ResourceLoader::expandUrl
+ * @covers ResourceLoaderFileModule
+ */
+ public function testGetScriptURLsForDebug() {
+ $ctx = $this->getResourceLoaderContext();
+ $module = new ResourceLoaderFileModule( [
+ 'localBasePath' => __DIR__ . '/../../data/resourceloader',
+ 'remoteBasePath' => '/w/something',
+ 'scripts' => [ 'script-comment.js' ],
+ ] );
+ $module->setName( 'testing' );
+ $module->setConfig( $ctx->getResourceLoader()->getConfig() );
+
+ $this->assertEquals(
+ [
+ 'https://example.org/w/something/script-comment.js'
+ ],
+ $module->getScriptURLsForDebug( $ctx )
+ );
+ }
+
+ /**
* @covers ResourceLoaderFileModule
*/
public function testGetAllSkinStyleFiles() {