From e9b9e4df7a53cd5367252adc57abc2b2a51d7d5d Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 4 Jun 2015 21:12:23 +0100 Subject: [PATCH] SpecialJavaScriptTest: Bypass ResourceLoader 'target' scope To make unit testing easier, allow any module to be loaded within the unit test suite. Regardless of the intended 'target'. Targets are meant for restricting front-end scope in production. Enforcing that in the test suite causes various test suites to get de-registered at run time client-side. Otherwise, in order to truly run all unit tests, Jenkins would have to re-run the entire test suite in all known targets. This wouldn't make sense because modules have to be globally uniquely named (no conflicts) and unit tests are atomic. They can all run in the same suite. To prevent modules being comitted with incompatible target dependencies, we already have a Structure test in the PHPUnit suite to catch those issues in the module registry. This makes the main 'qunit' build for MobileFrontend more useful, where currently many modules aren't being tested due to them not being in the 'desktop' target. Bug: T103027 Change-Id: I69f735eb56c1362189298d9859d3add576faaadb --- includes/resourceloader/ResourceLoaderStartUpModule.php | 5 ++++- includes/specials/SpecialJavaScriptTest.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index 16424a0031..cc35266c57 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -187,6 +187,9 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { $resourceLoader = $context->getResourceLoader(); $target = $context->getRequest()->getVal( 'target', 'desktop' ); + // Bypass target filter if this request is from a unit test context. To prevent misuse in + // production, this is only allowed if testing is enabled server-side. + $byPassTargetFilter = $this->getConfig()->get( 'EnableJavaScriptTest' ) && $target === 'test'; $out = ''; $registryData = array(); @@ -195,7 +198,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { foreach ( $resourceLoader->getModuleNames() as $name ) { $module = $resourceLoader->getModule( $name ); $moduleTargets = $module->getTargets(); - if ( !in_array( $target, $moduleTargets ) ) { + if ( !$byPassTargetFilter && !in_array( $target, $moduleTargets ) ) { continue; } diff --git a/includes/specials/SpecialJavaScriptTest.php b/includes/specials/SpecialJavaScriptTest.php index 442b7642cf..801f977e1d 100644 --- a/includes/specials/SpecialJavaScriptTest.php +++ b/includes/specials/SpecialJavaScriptTest.php @@ -205,6 +205,7 @@ HTML; 'lang' => $this->getLanguage()->getCode(), 'skin' => $this->getSkin()->getSkinName(), 'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false', + 'target' => 'test', ); $embedContext = new ResourceLoaderContext( $rl, new FauxRequest( $query ) ); $query['only'] = 'scripts'; -- 2.20.1