Merge "Replace uses of deprecated MediaWiki\Message\Converter"
[mediawiki.git] / tests / qunit / data / load.mock.php
blobc76daba528989eec7d4122114a990fd03113b007
1 <?php
2 /**
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
20 * @file
21 * @author Lupo
24 // This file doesn't run as part of MediaWiki
25 // phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
27 header( 'Cache-Control: private, no-cache, must-revalidate' );
28 header( 'Content-Type: text/javascript; charset=utf-8' );
30 $moduleImplementations = [
31 'testUsesMissing' => "
32 mw.loader.implement( 'testUsesMissing', function () {
33 mw.loader.testFail( 'Module usesMissing script should not run.' );
34 }, {}, {});
37 'testUsesNestedMissing' => "
38 mw.loader.implement( 'testUsesNestedMissing', function () {
39 mw.loader.testFail('Module testUsesNestedMissing script should not run.' );
40 }, {}, {});
43 'testSkipped' => "
44 mw.loader.implement( 'testSkipped', function () {
45 mw.loader.testFail( false, 'Module testSkipped was supposed to be skipped.' );
46 }, {}, {});
49 'testNotSkipped' => "
50 mw.loader.implement( 'testNotSkipped', function () {}, {}, {});
53 'testUsesSkippable' => "
54 mw.loader.implement( 'testUsesSkippable', function () {}, {}, {});
57 'testUrlInc' => "
58 mw.loader.implement( 'testUrlInc', function () {} );
60 'testUrlInc.a' => "
61 mw.loader.implement( 'testUrlInc.a', function () {} );
63 'testUrlInc.b' => "
64 mw.loader.implement( 'testUrlInc.b', function () {} );
66 'testUrlOrder' => "
67 mw.loader.implement( 'testUrlOrder', function () {} );
69 'testUrlOrder.a' => "
70 mw.loader.implement( 'testUrlOrder.a', function () {} );
72 'testUrlOrder.b' => "
73 mw.loader.implement( 'testUrlOrder.b', function () {} );
77 $response = '';
79 // Does not support the full behaviour of the real load.php.
80 // This only supports dotless module names joined by comma,
81 // with the exception of the hardcoded cases for testUrl*.
82 if ( isset( $_GET['modules'] ) ) {
83 if ( $_GET['modules'] === 'testUrlInc,testUrlIncDump|testUrlInc.a,b' ) {
84 $modules = [ 'testUrlInc', 'testUrlIncDump', 'testUrlInc.a', 'testUrlInc.b' ];
85 } elseif ( $_GET['modules'] === 'testUrlOrder,testUrlOrderDump|testUrlOrder.a,b' ) {
86 $modules = [ 'testUrlOrder', 'testUrlOrderDump', 'testUrlOrder.a', 'testUrlOrder.b' ];
87 } else {
88 $modules = explode( ',', $_GET['modules'] );
90 foreach ( $modules as $module ) {
91 if ( isset( $moduleImplementations[$module] ) ) {
92 $response .= $moduleImplementations[$module];
93 } elseif ( preg_match( '/^test.*Dump$/', $module ) === 1 ) {
94 $queryModules = $_GET['modules'];
95 $queryVersion = isset( $_GET['version'] ) ? strval( $_GET['version'] ) : null;
96 $response .= 'mw.loader.implement( ' . json_encode( $module )
97 . ', function ( $, jQuery, require, module ) {'
98 . 'module.exports.query = { '
99 . 'modules: ' . json_encode( $queryModules ) . ','
100 . 'version: ' . json_encode( $queryVersion )
101 . ' };'
102 . '} );';
103 } else {
104 // Default
105 $response .= 'mw.loader.state(' . json_encode( [ $module => 'missing' ] ) . ');' . "\n";
110 echo $response;