3 * Mock load.php with pre-defined test modules.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 // This file doesn't run as part of MediaWiki
25 // phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
27 header( 'Content-Type: text/javascript; charset=utf-8' );
29 $moduleImplementations = [
30 'testUsesMissing' => "
31 mw.loader.implement( 'testUsesMissing', function () {
32 mw.loader.testFail( 'Module usesMissing script should not run.' );
36 'testUsesNestedMissing' => "
37 mw.loader.implement( 'testUsesNestedMissing', function () {
38 mw.loader.testFail('Module testUsesNestedMissing script should not run.' );
43 mw.loader.implement( 'testSkipped', function () {
44 mw.loader.testFail( false, 'Module testSkipped was supposed to be skipped.' );
49 mw.loader.implement( 'testNotSkipped', function () {}, {}, {});
52 'testUsesSkippable' => "
53 mw.loader.implement( 'testUsesSkippable', function () {}, {}, {});
57 mw.loader.implement( 'testUrlInc', function () {} );
60 mw.loader.implement( 'testUrlInc.a', function () {} );
63 mw.loader.implement( 'testUrlInc.b', function () {} );
66 mw.loader.implement( 'testUrlOrder', function () {} );
69 mw.loader.implement( 'testUrlOrder.a', function () {} );
72 mw.loader.implement( 'testUrlOrder.b', function () {} );
78 // Does not support the full behaviour of the real load.php.
79 // This only supports dotless module names joined by comma,
80 // with the exception of the hardcoded cases for testUrl*.
81 if ( isset( $_GET['modules'] ) ) {
82 if ( $_GET['modules'] === 'testUrlInc,testUrlIncDump|testUrlInc.a,b' ) {
83 $modules = [ 'testUrlInc', 'testUrlIncDump', 'testUrlInc.a', 'testUrlInc.b' ];
84 } elseif ( $_GET['modules'] === 'testUrlOrder,testUrlOrderDump|testUrlOrder.a,b' ) {
85 $modules = [ 'testUrlOrder', 'testUrlOrderDump', 'testUrlOrder.a', 'testUrlOrder.b' ];
87 $modules = explode( ',', $_GET['modules'] );
89 foreach ( $modules as $module ) {
90 if ( isset( $moduleImplementations[$module] ) ) {
91 $response .= $moduleImplementations[$module];
92 } elseif ( preg_match( '/^test.*Dump$/', $module ) === 1 ) {
93 $queryModules = $_GET['modules'];
94 $queryVersion = isset( $_GET['version'] ) ?
strval( $_GET['version'] ) : null;
95 $response .= 'mw.loader.implement( ' . json_encode( $module )
96 . ', function ( $, jQuery, require, module ) {'
97 . 'module.exports.query = { '
98 . 'modules: ' . json_encode( $queryModules ) . ','
99 . 'version: ' . json_encode( $queryVersion )
104 $response .= 'mw.loader.state(' . json_encode( [ $module => 'missing' ] ) . ');' . "\n";