MediaWiki  1.23.1
SpecialJavaScriptTest.php
Go to the documentation of this file.
1 <?php
28 
34  static $frameworks = array(
35  'qunit' => 'initQUnitTesting',
36  );
37 
38  public function __construct() {
39  parent::__construct( 'JavaScriptTest' );
40  }
41 
42  public function execute( $par ) {
43  $out = $this->getOutput();
44 
45  $this->setHeaders();
46  $out->disallowUserJs();
47 
48  $out->addModules( 'mediawiki.special.javaScriptTest' );
49 
50  // Determine framework
51  $pars = explode( '/', $par );
52  $framework = strtolower( $pars[0] );
53 
54  // No framework specified
55  if ( $par == '' ) {
56  $out->setPageTitle( $this->msg( 'javascripttest' ) );
57  $summary = $this->wrapSummaryHtml(
58  $this->msg( 'javascripttest-pagetext-noframework' )->escaped() .
59  $this->getFrameworkListHtml(),
60  'noframework'
61  );
62  $out->addHtml( $summary );
63  } elseif ( isset( self::$frameworks[$framework] ) ) {
64  // Matched! Display proper title and initialize the framework
65  $out->setPageTitle( $this->msg(
66  'javascripttest-title',
67  // Messages: javascripttest-qunit-name
68  $this->msg( "javascripttest-$framework-name" )->plain()
69  ) );
70  $out->setSubtitle( $this->msg( 'javascripttest-backlink' )
71  ->rawParams( Linker::linkKnown( $this->getPageTitle() ) ) );
72  $this->{self::$frameworks[$framework]}();
73  } else {
74  // Framework not found, display error
75  $out->setPageTitle( $this->msg( 'javascripttest' ) );
76  $summary = $this->wrapSummaryHtml(
77  '<p class="error">' .
78  $this->msg( 'javascripttest-pagetext-unknownframework', $par )->escaped() .
79  '</p>' .
80  $this->getFrameworkListHtml(),
81  'unknownframework'
82  );
83  $out->addHtml( $summary );
84  }
85  }
86 
93  private function getFrameworkListHtml() {
94  $list = '<ul>';
95  foreach ( self::$frameworks as $framework => $initFn ) {
96  $list .= Html::rawElement(
97  'li',
98  array(),
100  $this->getPageTitle( $framework ),
101  // Message: javascripttest-qunit-name
102  $this->msg( "javascripttest-$framework-name" )->escaped()
103  )
104  );
105  }
106  $list .= '</ul>';
107 
108  return $this->msg( 'javascripttest-pagetext-frameworks' )->rawParams( $list )
109  ->parseAsBlock();
110  }
111 
121  private function wrapSummaryHtml( $html, $state ) {
122  $validStates = array( 'noframework', 'unknownframework', 'frameworkfound' );
123 
124  if ( !in_array( $state, $validStates ) ) {
125  throw new MWException( __METHOD__
126  . ' given an invalid state. Must be one of "'
127  . join( '", "', $validStates ) . '".'
128  );
129  }
130 
131  return "<div id=\"mw-javascripttest-summary\" class=\"mw-javascripttest-$state\">$html</div>";
132  }
133 
137  private function initQUnitTesting() {
138  global $wgJavaScriptTestConfig;
139 
140  $out = $this->getOutput();
141 
142  $out->addModules( 'test.mediawiki.qunit.testrunner' );
143  $qunitTestModules = $out->getResourceLoader()->getTestModuleNames( 'qunit' );
144  $out->addModules( $qunitTestModules );
145 
146  $summary = $this->msg( 'javascripttest-qunit-intro' )
147  ->params( $wgJavaScriptTestConfig['qunit']['documentation'] )
148  ->parseAsBlock();
149  $header = $this->msg( 'javascripttest-qunit-heading' )->escaped();
150  $userDir = $this->getLanguage()->getDir();
151 
152  $baseHtml = <<<HTML
153 <div class="mw-content-ltr">
154 <div id="qunit-header"><span dir="$userDir">$header</span></div>
155 <div id="qunit-banner"></div>
156 <div id="qunit-testrunner-toolbar"></div>
157 <div id="qunit-userAgent"></div>
158 <ol id="qunit-tests"></ol>
159 <div id="qunit-fixture">test markup, will be hidden</div>
160 </div>
161 HTML;
162  $out->addHtml( $this->wrapSummaryHtml( $summary, 'frameworkfound' ) . $baseHtml );
163 
164  // This special page is disabled by default ($wgEnableJavaScriptTest), and contains
165  // no sensitive data. In order to allow TestSwarm to embed it into a test client window,
166  // we need to allow iframing of this page.
167  $out->allowClickjacking();
168 
169  // Used in ./tests/qunit/data/testrunner.js, see also documentation of
170  // $wgJavaScriptTestConfig in DefaultSettings.php
171  $out->addJsConfigVars(
172  'QUnitTestSwarmInjectJSPath',
173  $wgJavaScriptTestConfig['qunit']['testswarm-injectjs']
174  );
175  }
176 
177  protected function getGroupName() {
178  return 'other';
179  }
180 }
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:488
SpecialJavaScriptTest\execute
execute( $par)
Default execute method Checks user permissions, calls the function given in mFunction.
Definition: SpecialJavaScriptTest.php:42
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
SpecialJavaScriptTest\$frameworks
static $frameworks
Definition: SpecialJavaScriptTest.php:34
SpecialJavaScriptTest\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialJavaScriptTest.php:177
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:578
SpecialJavaScriptTest\wrapSummaryHtml
wrapSummaryHtml( $html, $state)
Function to wrap the summary.
Definition: SpecialJavaScriptTest.php:121
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
MWException
MediaWiki exception.
Definition: MWException.php:26
$out
$out
Definition: UtfNormalGenerate.php:167
SpecialJavaScriptTest\__construct
__construct()
Definition: SpecialJavaScriptTest.php:38
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
will
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
Definition: All_system_messages.txt:914
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialJavaScriptTest
Definition: SpecialJavaScriptTest.php:27
$summary
$summary
Definition: importImages.php:120
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SpecialJavaScriptTest\initQUnitTesting
initQUnitTesting()
Initialize the page for QUnit.
Definition: SpecialJavaScriptTest.php:137
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
SpecialJavaScriptTest\getFrameworkListHtml
getFrameworkListHtml()
Get a list of frameworks (including introduction paragraph and links to the framework run pages)
Definition: SpecialJavaScriptTest.php:93