wiki.techinc.nl/tests/qunit/data/load.mock.php
Timo Tijhof 75c08916b0 resourceloader: Implement "skip function" feature
A module can be registered with a skip function. Such function,
if provided, will be invoked by the client when a module is
queued for loading. If the function returns true, the client will
bypass any further loading action and mark the module as 'ready'.

This can be used to implement a feature test for a module
providing a shim or polyfill.

* Change visibility of method ResourceLoader::filter to public.

So that it can be invoked by ResourceLoaderStartupModule.

* Add option to suppress the cache key report in ResourceLoader::filter.

We usually only call the minifier once on an entire request
reponse (because it's all concatenated javascript or embedded
javascript in various different closures, still valid as one
large script) and only add a little bottom line for the cache
key. When embedding the skip function we have to run the minifier
on them separately as they're output as strings (not actual
functions). These strings are typically quite small and blowing
up the response with loads of cache keys is not desirable in
production.

* Add method to clear the static cache of ResourceLoader::inDebugMode.

Global static state is evil but, as long as we have it, we at
least need to clear it after switching contexts in the test suite.

Also:
* Remove obsolete setting of 'debug=true' in the FauxRequest in
  ResourceLoaderTestCase. It already sets global wgResourceLoaderDebug
  in the setUp() method.

Bug: 66390
Change-Id: I87a0ea888d791ad39f114380c42e2daeca470961
2014-06-12 03:48:26 +02:00

74 lines
2.2 KiB
PHP

<?php
/**
* Mock load.php with pre-defined test modules.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @package MediaWiki
* @author Lupo
* @since 1.20
*/
header( 'Content-Type: text/javascript; charset=utf-8' );
require_once __DIR__ . '/../../../includes/json/FormatJson.php';
require_once __DIR__ . '/../../../includes/Xml.php';
$moduleImplementations = array(
'testUsesMissing' => "
mw.loader.implement( 'testUsesMissing', function () {
QUnit.ok( false, 'Module usesMissing script should not run.' );
QUnit.start();
}, {}, {});
",
'testUsesNestedMissing' => "
mw.loader.implement( 'testUsesNestedMissing', function () {
QUnit.ok( false, 'Module testUsesNestedMissing script should not run.' );
QUnit.start();
}, {}, {});
",
'testSkipped' =>"
mw.loader.implement( 'testSkipped', function () {
QUnit.ok( false, 'Module testSkipped was supposed to be skipped.' );
}, {}, {});
",
'testNotSkipped' =>"
mw.loader.implement( 'testNotSkipped', function () {}, {}, {});
",
'testUsesSkippable' =>"
mw.loader.implement( 'testUsesSkippable', function () {}, {}, {});
",
);
$response = '';
// Only support for non-encoded module names, full module names expected
if ( isset( $_GET['modules'] ) ) {
$modules = explode( ',', $_GET['modules'] );
foreach ( $modules as $module ) {
if ( isset( $moduleImplementations[$module] ) ) {
$response .= $moduleImplementations[$module];
} else {
$response .= Xml::encodeJsCall( 'mw.loader.state', array( $module, 'missing' ), true );
}
}
}
echo $response;