2012-01-03 18:33:26 +00:00
|
|
|
<?php
|
2012-02-09 09:34:47 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup SpecialPage
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2012-01-03 18:33:26 +00:00
|
|
|
|
2012-02-09 09:34:47 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup SpecialPage
|
|
|
|
|
*/
|
2012-01-03 18:33:26 +00:00
|
|
|
class SpecialJavaScriptTest extends SpecialPage {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var $frameworks Array: Mapping of framework ids and their initilizer methods
|
|
|
|
|
* in this class. If a framework is requested but not in this array,
|
|
|
|
|
* the 'unknownframework' error is served.
|
|
|
|
|
*/
|
|
|
|
|
static $frameworks = array(
|
|
|
|
|
'qunit' => 'initQUnitTesting',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct( 'JavaScriptTest' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute( $par ) {
|
|
|
|
|
global $wgEnableJavaScriptTest;
|
|
|
|
|
|
|
|
|
|
$out = $this->getOutput();
|
|
|
|
|
|
|
|
|
|
$this->setHeaders();
|
|
|
|
|
$out->disallowUserJs();
|
|
|
|
|
|
|
|
|
|
// Abort early if we're disabled
|
|
|
|
|
if ( $wgEnableJavaScriptTest !== true ) {
|
|
|
|
|
$out->addWikiMsg( 'javascripttest-disabled' );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$out->addModules( 'mediawiki.special.javaScriptTest' );
|
|
|
|
|
|
|
|
|
|
// Determine framework
|
|
|
|
|
$pars = explode( '/', $par );
|
|
|
|
|
$framework = strtolower( $pars[0] );
|
|
|
|
|
|
|
|
|
|
// No framework specified
|
|
|
|
|
if ( $par == '' ) {
|
2012-02-10 19:46:04 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'javascripttest' ) );
|
2012-01-03 18:33:26 +00:00
|
|
|
$summary = $this->wrapSummaryHtml(
|
2012-02-10 19:46:04 +00:00
|
|
|
$this->msg( 'javascripttest-pagetext-noframework' )->escaped() . $this->getFrameworkListHtml(),
|
2012-01-03 18:33:26 +00:00
|
|
|
'noframework'
|
|
|
|
|
);
|
|
|
|
|
$out->addHtml( $summary );
|
|
|
|
|
|
|
|
|
|
// Matched! Display proper title and initialize the framework
|
|
|
|
|
} elseif ( isset( self::$frameworks[$framework] ) ) {
|
2012-02-10 19:46:04 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'javascripttest-title', $this->msg( "javascripttest-$framework-name" )->plain() ) );
|
|
|
|
|
$out->setSubtitle( $this->msg( 'javascripttest-backlink' )->rawParams( Linker::linkKnown( $this->getTitle() ) ) );
|
2012-01-03 18:33:26 +00:00
|
|
|
$this->{self::$frameworks[$framework]}();
|
|
|
|
|
|
|
|
|
|
// Framework not found, display error
|
|
|
|
|
} else {
|
2012-02-10 19:46:04 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'javascripttest' ) );
|
2012-01-03 18:33:26 +00:00
|
|
|
$summary = $this->wrapSummaryHtml( '<p class="error">'
|
2012-02-10 19:46:04 +00:00
|
|
|
. $this->msg( 'javascripttest-pagetext-unknownframework', $par )->escaped()
|
2012-01-03 18:33:26 +00:00
|
|
|
. '</p>'
|
2012-01-04 10:31:02 +00:00
|
|
|
. $this->getFrameworkListHtml(),
|
|
|
|
|
'unknownframework'
|
|
|
|
|
);
|
|
|
|
|
$out->addHtml( $summary );
|
2012-01-03 18:33:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a list of frameworks (including introduction paragraph and links to the framework run pages)
|
|
|
|
|
* @return String: HTML
|
|
|
|
|
*/
|
|
|
|
|
private function getFrameworkListHtml() {
|
|
|
|
|
$list = '<ul>';
|
|
|
|
|
foreach( self::$frameworks as $framework => $initFn ) {
|
|
|
|
|
$list .= Html::rawElement(
|
|
|
|
|
'li',
|
|
|
|
|
array(),
|
2012-02-10 19:46:04 +00:00
|
|
|
Linker::link( $this->getTitle( $framework ), $this->msg( "javascripttest-$framework-name" )->escaped() )
|
2012-01-03 18:33:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$list .= '</ul>';
|
2012-02-10 19:46:04 +00:00
|
|
|
$msg = $this->msg( 'javascripttest-pagetext-frameworks' )->rawParams( $list )->parseAsBlock();
|
2012-01-03 18:33:26 +00:00
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function to wrap the summary.
|
2012-01-04 10:31:02 +00:00
|
|
|
* It must be given a valid state as a second parameter or an exception will
|
|
|
|
|
* be thrown.
|
2012-01-03 18:33:26 +00:00
|
|
|
* @param $html String: The raw HTML.
|
|
|
|
|
* @param $state String: State, one of 'noframework', 'unknownframework' or 'frameworkfound'
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return string
|
2012-01-03 18:33:26 +00:00
|
|
|
*/
|
2012-01-04 10:31:02 +00:00
|
|
|
private function wrapSummaryHtml( $html, $state ) {
|
|
|
|
|
$validStates = array( 'noframework', 'unknownframework', 'frameworkfound' );
|
|
|
|
|
if( !in_array( $state, $validStates ) ) {
|
|
|
|
|
throw new MWException( __METHOD__
|
|
|
|
|
. ' given an invalid state. Must be one of "'
|
|
|
|
|
. join( '", "', $validStates) . '".'
|
|
|
|
|
);
|
|
|
|
|
}
|
2012-01-03 18:33:26 +00:00
|
|
|
return "<div id=\"mw-javascripttest-summary\" class=\"mw-javascripttest-$state\">$html</div>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize the page for QUnit.
|
|
|
|
|
*/
|
|
|
|
|
private function initQUnitTesting() {
|
2012-02-10 19:46:04 +00:00
|
|
|
global $wgJavaScriptTestConfig;
|
2012-01-03 18:33:26 +00:00
|
|
|
|
|
|
|
|
$out = $this->getOutput();
|
|
|
|
|
|
|
|
|
|
$out->addModules( 'mediawiki.tests.qunit.testrunner' );
|
|
|
|
|
$qunitTestModules = $out->getResourceLoader()->getTestModuleNames( 'qunit' );
|
|
|
|
|
$out->addModules( $qunitTestModules );
|
|
|
|
|
|
2012-02-10 19:46:04 +00:00
|
|
|
$summary = $this->msg( 'javascripttest-qunit-intro' )
|
2012-01-03 18:33:26 +00:00
|
|
|
->params( $wgJavaScriptTestConfig['qunit']['documentation'] )
|
|
|
|
|
->parseAsBlock();
|
2012-02-10 19:46:04 +00:00
|
|
|
$header = $this->msg( 'javascripttest-qunit-heading' )->escaped();
|
|
|
|
|
$userDir = $this->getLanguage()->getDir();
|
2012-01-03 18:33:26 +00:00
|
|
|
|
|
|
|
|
$baseHtml = <<<HTML
|
2012-01-17 00:23:07 +00:00
|
|
|
<div class="mw-content-ltr">
|
|
|
|
|
<div id="qunit-header"><span dir="$userDir">$header</span></div>
|
2012-01-03 18:33:26 +00:00
|
|
|
<div id="qunit-banner"></div>
|
|
|
|
|
<div id="qunit-testrunner-toolbar"></div>
|
|
|
|
|
<div id="qunit-userAgent"></div>
|
|
|
|
|
<ol id="qunit-tests"></ol>
|
2012-01-21 06:18:38 +00:00
|
|
|
<div id="qunit-fixture">test markup, will be hidden</div>
|
2012-01-17 00:23:07 +00:00
|
|
|
</div>
|
2012-01-03 18:33:26 +00:00
|
|
|
HTML;
|
|
|
|
|
$out->addHtml( $this->wrapSummaryHtml( $summary, 'frameworkfound' ) . $baseHtml );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isListed(){
|
|
|
|
|
global $wgEnableJavaScriptTest;
|
|
|
|
|
return $wgEnableJavaScriptTest === true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|