MediaWiki REL1_31
load.mock.php
Go to the documentation of this file.
1<?php
25header( 'Content-Type: text/javascript; charset=utf-8' );
26
28 'testUsesMissing' => "
29mw.loader.implement( 'testUsesMissing', function () {
30 mw.loader.testFail( 'Module usesMissing script should not run.' );
31}, {}, {});
32",
33
34 'testUsesNestedMissing' => "
35mw.loader.implement( 'testUsesNestedMissing', function () {
36 mw.loader.testFail('Module testUsesNestedMissing script should not run.' );
37}, {}, {});
38",
39
40 'testSkipped' => "
41mw.loader.implement( 'testSkipped', function () {
42 mw.loader.testFail( false, 'Module testSkipped was supposed to be skipped.' );
43}, {}, {});
44",
45
46 'testNotSkipped' => "
47mw.loader.implement( 'testNotSkipped', function () {}, {}, {});
48",
49
50 'testUsesSkippable' => "
51mw.loader.implement( 'testUsesSkippable', function () {}, {}, {});
52",
53
54 'testUrlInc' => "
55mw.loader.implement( 'testUrlInc', function () {} );
56",
57 'testUrlInc.a' => "
58mw.loader.implement( 'testUrlInc.a', function () {} );
59",
60 'testUrlInc.b' => "
61mw.loader.implement( 'testUrlInc.b', function () {} );
62",
63 'testUrlOrder' => "
64mw.loader.implement( 'testUrlOrder', function () {} );
65",
66 'testUrlOrder.a' => "
67mw.loader.implement( 'testUrlOrder.a', function () {} );
68",
69 'testUrlOrder.b' => "
70mw.loader.implement( 'testUrlOrder.b', function () {} );
71",
72];
73
75
76// Does not support the full behaviour of ResourceLoaderContext::expandModuleNames(),
77// Only supports dotless module names joined by comma,
78// with the exception of the hardcoded cases for testUrl*.
79if ( isset( $_GET['modules'] ) ) {
80 if ( $_GET['modules'] === 'testUrlInc,testUrlIncDump|testUrlInc.a,b' ) {
81 $modules = [ 'testUrlInc', 'testUrlIncDump', 'testUrlInc.a', 'testUrlInc.b' ];
82 } elseif ( $_GET['modules'] === 'testUrlOrder,testUrlOrderDump|testUrlOrder.a,b' ) {
83 $modules = [ 'testUrlOrder', 'testUrlOrderDump', 'testUrlOrder.a', 'testUrlOrder.b' ];
84 } else {
85 $modules = explode( ',', $_GET['modules'] );
86 }
87 foreach ( $modules as $module ) {
88 if ( isset( $moduleImplementations[$module] ) ) {
90 } elseif ( preg_match( '/^test.*Dump$/', $module ) === 1 ) {
91 $queryModules = $_GET['modules'];
92 $queryVersion = isset( $_GET['version'] ) ? strval( $_GET['version'] ) : null;
93 $response .= 'mw.loader.implement( ' . json_encode( $module )
94 . ', function ( $, jQuery, require, module ) {'
95 . 'module.exports.query = { '
96 . 'modules: ' . json_encode( $queryModules ) . ','
97 . 'version: ' . json_encode( $queryVersion )
98 . ' };'
99 . '} );';
100 } else {
101 // Default
102 $response .= 'mw.loader.state(' . json_encode( $module ) . ', "missing" );' . "\n";
103 }
104 }
105}
106
107echo $response;
$moduleImplementations
Definition load.mock.php:27
$response
Definition load.mock.php:74