resourceloader: Support TestModules registration via extension.json
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoader.php
index 2fc81e3..f05c8c8 100644 (file)
@@ -408,24 +408,24 @@ class ResourceLoader implements LoggerAwareInterface {
                                . 'Edit your <code>LocalSettings.php</code> to enable it.' );
                }
 
-               // Get core test suites
-               $testModules = [];
-               $testModules['qunit'] = [];
-               // Get other test suites (e.g. from extensions)
+               $testModules = [
+                       'qunit' => [],
+               ];
+
+               // Get test suites from extensions
                // Avoid PHP 7.1 warning from passing $this by reference
                $rl = $this;
                Hooks::run( 'ResourceLoaderTestModules', [ &$testModules, &$rl ] );
+               $extRegistry = ExtensionRegistry::getInstance();
+               // In case of conflict, the deprecated hook has precedence.
+               $testModules['qunit'] += $extRegistry->getAttribute( 'QUnitTestModules' );
 
-               // Add the testrunner (which configures QUnit) to the dependencies.
-               // Since it must be ready before any of the test suites are executed.
+               // Add the QUnit testrunner as implicit dependency to extension test suites.
                foreach ( $testModules['qunit'] as &$module ) {
-                       // Make sure all test modules are top-loading so that when QUnit starts
-                       // on document-ready, it will run once and finish. If some tests arrive
-                       // later (possibly after QUnit has already finished) they will be ignored.
-                       $module['position'] = 'top';
                        $module['dependencies'][] = 'test.mediawiki.qunit.testrunner';
                }
 
+               // Get core test suites
                $testModules['qunit'] =
                        ( include "$IP/tests/qunit/QUnitTestResources.php" ) + $testModules['qunit'];
 
@@ -781,7 +781,7 @@ class ResourceLoader implements LoggerAwareInterface {
                }
 
                // Save response to file cache unless there are errors
-               if ( isset( $fileCache ) && !$this->errors && !count( $missing ) ) {
+               if ( isset( $fileCache ) && !$this->errors && $missing === [] ) {
                        // Cache single modules and images...and other requests if there are enough hits
                        if ( ResourceFileCache::useFileCache( $context ) ) {
                                if ( $fileCache->isCacheWorthy() ) {
@@ -1036,7 +1036,7 @@ class ResourceLoader implements LoggerAwareInterface {
                $out = '';
                $states = [];
 
-               if ( !count( $modules ) && !count( $missing ) ) {
+               if ( $modules === [] && $missing === [] ) {
                        return <<<MESSAGE
 /* This file is the Web entry point for MediaWiki's ResourceLoader:
    <https://www.mediawiki.org/wiki/ResourceLoader>. In this request,
@@ -1529,10 +1529,12 @@ MESSAGE;
                        self::inDebugMode()
                );
                if ( $js === false ) {
-                       throw new Exception(
+                       $e = new Exception(
                                'JSON serialization of config data failed. ' .
                                'This usually means the config data is not valid UTF-8.'
                        );
+                       MWExceptionHandler::logException( $e );
+                       $js = Xml::encodeJsCall( 'mw.log.error', [ $e->__toString() ] );
                }
                return $js;
        }