. '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'];
$object->setConfig( $this->getConfig() );
$object->setLogger( $this->logger );
} else {
- if ( !isset( $info['class'] ) ) {
- $class = ResourceLoaderFileModule::class;
- } else {
- $class = $info['class'];
- }
+ $class = $info['class'] ?? ResourceLoaderFileModule::class;
/** @var ResourceLoaderModule $object */
$object = new $class( $info );
$object->setConfig( $this->getConfig() );
}
// 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() ) {
$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,
* - new XmlJsCode( '{}' )
* - new stdClass() // (object) []
*
- * @param Array $array
+ * @param array $array
*/
private static function trimArray( array &$array ) {
$i = count( $array );
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;
}