Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / qunit / data / load.mock.php
1 <?php
2 /**
3 * Mock load.php with pre-defined test modules.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Lupo
22 */
23
24 // This file doesn't run as part of MediaWiki
25 // phpcs:disable MediaWiki.Usage.SuperGlobalsUsage.SuperGlobals
26
27 header( 'Content-Type: text/javascript; charset=utf-8' );
28
29 $moduleImplementations = [
30 'testUsesMissing' => "
31 mw.loader.implement( 'testUsesMissing', function () {
32 mw.loader.testFail( 'Module usesMissing script should not run.' );
33 }, {}, {});
34 ",
35
36 'testUsesNestedMissing' => "
37 mw.loader.implement( 'testUsesNestedMissing', function () {
38 mw.loader.testFail('Module testUsesNestedMissing script should not run.' );
39 }, {}, {});
40 ",
41
42 'testSkipped' => "
43 mw.loader.implement( 'testSkipped', function () {
44 mw.loader.testFail( false, 'Module testSkipped was supposed to be skipped.' );
45 }, {}, {});
46 ",
47
48 'testNotSkipped' => "
49 mw.loader.implement( 'testNotSkipped', function () {}, {}, {});
50 ",
51
52 'testUsesSkippable' => "
53 mw.loader.implement( 'testUsesSkippable', function () {}, {}, {});
54 ",
55
56 'testUrlInc' => "
57 mw.loader.implement( 'testUrlInc', function () {} );
58 ",
59 'testUrlInc.a' => "
60 mw.loader.implement( 'testUrlInc.a', function () {} );
61 ",
62 'testUrlInc.b' => "
63 mw.loader.implement( 'testUrlInc.b', function () {} );
64 ",
65 'testUrlOrder' => "
66 mw.loader.implement( 'testUrlOrder', function () {} );
67 ",
68 'testUrlOrder.a' => "
69 mw.loader.implement( 'testUrlOrder.a', function () {} );
70 ",
71 'testUrlOrder.b' => "
72 mw.loader.implement( 'testUrlOrder.b', function () {} );
73 ",
74 ];
75
76 $response = '';
77
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' ];
86 } else {
87 $modules = explode( ',', $_GET['modules'] );
88 }
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 )
100 . ' };'
101 . '} );';
102 } else {
103 // Default
104 $response .= 'mw.loader.state(' . json_encode( [ $module => 'missing' ] ) . ');' . "\n";
105 }
106 }
107 }
108
109 echo $response;