34 parent::__construct(
'JavaScriptTest' );
40 if ( $par ===
'qunit/export' ) {
43 } elseif ( $par ===
null || $par ===
'' || $par ===
'qunit' || $par ===
'qunit/plain' ) {
48 wfHttpError( 404,
'Unknown action',
"Unknown action \"$par\"." );
57 private function exportJS() {
59 $rl = $out->getResourceLoader();
63 $out->setPreventClickjacking(
false );
68 'debug' => (string)ResourceLoader::inDebugMode(),
72 $query[
'only'] =
'scripts';
75 $modules = $rl->getTestSuiteModuleNames();
76 $component = $this->
getContext()->getRequest()->getVal(
'component' );
78 $module =
'test.' . $component;
79 if ( !in_array(
'test.' . $component,
$modules ) ) {
82 'Unknown test module',
83 "'$module' is not a defined test module. "
84 .
'Register one via the QUnitTestModules attribute in extension.json.'
94 new HashConfig( [ MainConfigNames::ResourceLoaderStorageEnabled =>
false ] ),
101 $qunitConfig =
'QUnit.config.autostart = false;'
102 .
'if (window.__karma__) {'
106 .
'window.__karma__.loaded = function () {};'
110 $startupModule = $rl->getModule(
'startup' );
111 $startupModule->setConfig( $config );
112 $code = $rl->makeModuleResponse( $startupContext, [
'startup' => $startupModule ] );
114 $code .= ResourceLoader::makeLoaderConditionalScript(
128 ResourceLoader::makeConfigSetScript( [
130 'wgPageName' =>
'Special:Badtitle/JavaScriptTest',
132 'wgRelevantPageName' =>
'Special:Badtitle/JavaScriptTest',
135 . $rl->makeModuleResponse( $embedContext, [
136 'user.options' => $rl->getModule(
'user.options' ),
139 . Xml::encodeJsCall(
'mw.loader.load', [
$modules ] )
142 $code .= ResourceLoader::makeInlineCodeWithModule(
'mediawiki.base', <<<JAVASCRIPT
143 var start = window.__karma__ ? window.__karma__.start : QUnit.start;
144 mw.loader.using( $encModules ).always( start );
145 mw.trackSubscribe(
'resourceloader.exception',
function ( topic, err ) {
148 setTimeout(
function () {
155 header(
'Content-Type: text/javascript; charset=utf-8' );
156 header(
'Cache-Control: private, no-cache, must-revalidate' );
157 header(
'Pragma: no-cache' );
162 private function renderPage() {
163 $basePath = $this->
getConfig()->get( MainConfigNames::ResourceBasePath );
164 $headHtml = implode(
"\n", [
165 Html::linkedScript(
"$basePath/resources/lib/qunitjs/qunit.js" ),
166 Html::linkedStyle(
"$basePath/resources/lib/qunitjs/qunit.css" ),
167 Html::linkedStyle(
"$basePath/resources/src/qunitjs/qunit-local.css" ),
170 $introHtml = $this->
msg(
'javascripttest-qunit-intro' )
171 ->params(
'https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing' )
174 $scriptUrl = $this->
getPageTitle(
'qunit/export' )->getFullURL( [
175 'debug' => (
string)ResourceLoader::inDebugMode(),
179 header(
'Content-Type: text/html; charset=utf-8' );
185<div
id=
"qunit"></div>
wfHttpError( $code, $label, $desc)
Provide a simple HTTP error.
WebRequest clone which takes values from a provided array.
A Config instance which stores all settings as a member variable.
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
A class containing constants representing the names of configuration variables.
Context object that contains information about the state of a specific ResourceLoader web request.
Provides a fallback sequence for Config objects.
execute( $par)
Default execute method Checks user permissions.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
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.
static encodeJsVar( $value, $pretty=false)
Encode a variable of arbitrary type to JavaScript.