30 parent::__construct(
'JavaScriptTest' );
37 $out->disallowUserJs();
42 $out->allowClickjacking();
45 if ( $par ===
'qunit/export' ) {
52 if ( $par ===
null || $par ===
'' || $par ===
'qunit' || $par ===
'qunit/plain' ) {
58 $out->setStatusCode( 404 );
59 $out->setPageTitle( $this->
msg(
'javascripttest' ) );
62 . $this->
msg(
'javascripttest-pagetext-unknownaction' )
63 ->plaintextParams( $par )->parseAsBlock()
74 $summary = $this->
msg(
'javascripttest-qunit-intro' )
75 ->params(
'https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing' )
77 return "<div id=\"mw-javascripttest-summary\">$summary</div>";
94 $rl = $out->getResourceLoader();
98 'skin' => $this->
getSkin()->getSkinName(),
99 'debug' => ResourceLoader::inDebugMode() ?
'true' :
'false',
103 $query[
'only'] =
'scripts';
106 $modules = $rl->getTestSuiteModuleNames();
111 $qunitConfig =
'QUnit.config.autostart = false;'
112 .
'if (window.__karma__) {'
116 .
'window.__karma__.loaded = function () {};'
120 $code = $rl->makeModuleResponse( $startupContext, [
121 'startup' => $rl->getModule(
'startup' ),
123 $code .= <<<JAVASCRIPT
127 mw.loader.store.enabled =
false;
130 $code .= ResourceLoader::makeLoaderConditionalScript(
134 ResourceLoader::makeConfigSetScript( $out->getJSVars() )
136 . $rl->makeModuleResponse( $embedContext, [
137 'user.options' => $rl->getModule(
'user.options' ),
138 'user.tokens' => $rl->getModule(
'user.tokens' ),
144 $code .= ResourceLoader::makeInlineCodeWithModule(
'mediawiki.base', <<<JAVASCRIPT
145 var start = window.__karma__ ? window.__karma__.start : QUnit.start;
146 mw.loader.using( $encModules ).always( start );
147 mw.trackSubscribe(
'resourceloader.exception',
function ( topic, err ) {
150 setTimeout(
function () {
157 header(
'Content-Type: text/javascript; charset=utf-8' );
158 header(
'Cache-Control: private, no-cache, must-revalidate' );
159 header(
'Pragma: no-cache' );
168 $styles = $out->makeResourceLoaderLink(
'jquery.qunit',
169 ResourceLoaderModule::TYPE_STYLES
175 $scripts = $out->makeResourceLoaderLink(
'jquery.qunit',
176 ResourceLoaderModule::TYPE_SCRIPTS,
177 [
'raw' =>
'1',
'sync' =>
'1' ]
180 $head = implode(
"\n", [ $styles, $scripts ] );
187 <div
id=
"qunit"></div>
190 $url = $this->
getPageTitle(
'qunit/export' )->getFullURL( [
191 'debug' => ResourceLoader::inDebugMode() ?
'true' :
'false',
193 $html .=
"\n" . Html::linkedScript( $url );
195 header(
'Content-Type: text/html; charset=utf-8' );