36 parent::__construct(
'JavaScriptTest' );
42 if ( $par ===
'qunit/export' ) {
45 } elseif ( $par ===
null || $par ===
'' || $par ===
'qunit' || $par ===
'qunit/plain' ) {
50 wfHttpError( 404,
'Unknown action',
"Unknown action \"$par\"." );
59 private function exportJS() {
61 $rl = $out->getResourceLoader();
65 $out->setPreventClickjacking(
false );
70 'debug' => (string)ResourceLoader::inDebugMode(),
74 $query[
'only'] =
'scripts';
77 $modules = $rl->getTestSuiteModuleNames();
78 $component = $this->
getContext()->getRequest()->getVal(
'component' );
80 $module =
'test.' . $component;
81 if ( !in_array(
'test.' . $component,
$modules ) ) {
84 'Unknown test module',
85 "'$module' is not a defined test module. "
86 .
'Register one via the QUnitTestModules attribute in extension.json.'
96 new HashConfig( [ MainConfigNames::ResourceLoaderStorageEnabled =>
false ] ),
103 $qunitConfig =
'QUnit.config.autostart = false;'
104 .
'if (window.__karma__) {'
108 .
'window.__karma__.loaded = function () {};'
112 $startupModule = $rl->getModule(
'startup' );
113 $startupModule->setConfig( $config );
114 $code = $rl->makeModuleResponse( $startupContext, [
'startup' => $startupModule ] );
116 $code .= ResourceLoader::makeLoaderConditionalScript(
130 ResourceLoader::makeConfigSetScript( [
132 'wgPageName' =>
'Special:Badtitle/JavaScriptTest',
134 'wgRelevantPageName' =>
'Special:Badtitle/JavaScriptTest',
137 . $rl->makeModuleResponse( $embedContext, [
138 'user.options' => $rl->getModule(
'user.options' ),
141 . Xml::encodeJsCall(
'mw.loader.load', [
$modules ] )
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' );
164 private function renderPage() {
165 $basePath = $this->
getConfig()->get( MainConfigNames::ResourceBasePath );
166 $headHtml = implode(
"\n", [
167 Html::linkedScript(
"$basePath/resources/lib/qunitjs/qunit.js" ),
168 Html::linkedStyle(
"$basePath/resources/lib/qunitjs/qunit.css" ),
169 Html::linkedStyle(
"$basePath/resources/src/qunitjs/qunit-local.css" ),
172 $introHtml = $this->
msg(
'javascripttest-qunit-intro' )
173 ->params(
'https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing' )
176 $scriptUrl = $this->
getPageTitle(
'qunit/export' )->getFullURL( [
177 'debug' => (
string)ResourceLoader::inDebugMode(),
179 $script = Html::linkedScript( $scriptUrl );
181 header(
'Content-Type: text/html; charset=utf-8' );
187<div
id=
"qunit"></div>
Parent class for all special pages.
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getPageTitle( $subpage=false)
Get a self-referential title object.