From be5a40b7e10244fb7ef074970192dfc130f08ce2 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 9 Jul 2015 20:40:27 -0700 Subject: [PATCH] Special:JavaScriptTest: Redirect to /qunit/plain by default Currently there's only one framework, so having an error landing page when visiting Special:JavaScriptTest isn't helpful. DWIM and send the user to Special:JavaScriptTest/qunit/plain if that is the only framework that is configured. Also add the testing help link to the "/plain" view. Change-Id: Ifc473d080ecf6f0a9add0510480ba9dad76050e9 --- includes/specials/SpecialJavaScriptTest.php | 35 +++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/includes/specials/SpecialJavaScriptTest.php b/includes/specials/SpecialJavaScriptTest.php index d330b0e846..4c73f1676e 100644 --- a/includes/specials/SpecialJavaScriptTest.php +++ b/includes/specials/SpecialJavaScriptTest.php @@ -44,6 +44,11 @@ class SpecialJavaScriptTest extends SpecialPage { if ( $par === null ) { // No framework specified + // If only one framework is configured, redirect to it. Otherwise display a list. + if ( count( self::$frameworks ) === 1 ) { + $out->redirect( $this->getPageTitle( self::$frameworks[0] . '/plain' )->getLocalURL() ); + return; + } $out->setStatusCode( 404 ); $out->setPageTitle( $this->msg( 'javascripttest' ) ); $out->addHTML( @@ -74,10 +79,14 @@ class SpecialJavaScriptTest extends SpecialPage { // no sensitive data. In order to allow TestSwarm to embed it into a test client window, // we need to allow iframing of this page. $out->allowClickjacking(); - $out->setSubtitle( - $this->msg( 'javascripttest-backlink' ) - ->rawParams( Linker::linkKnown( $this->getPageTitle() ) ) - ); + if ( count( self::$frameworks ) !== 1 ) { + // If there's only one framework, don't set the subtitle since it + // is going to redirect back to this page + $out->setSubtitle( + $this->msg( 'javascripttest-backlink' ) + ->rawParams( Linker::linkKnown( $this->getPageTitle() ) ) + ); + } // Custom actions if ( isset( $pars[1] ) ) { @@ -134,13 +143,15 @@ class SpecialJavaScriptTest extends SpecialPage { } /** - * Wrap HTML contents in a summary container. + * Get summary text wrapped in a container * - * @param string $html HTML contents to be wrapped * @return string HTML */ - private function wrapSummaryHtml( $html ) { - return "
$html
"; + private function getSummaryHtml() { + $summary = $this->msg( 'javascripttest-qunit-intro' ) + ->params( 'https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing' ) + ->parseAsBlock(); + return "
$summary
"; } /** @@ -153,17 +164,13 @@ class SpecialJavaScriptTest extends SpecialPage { $modules = $out->getResourceLoader()->getTestModuleNames( 'qunit' ); - $summary = $this->msg( 'javascripttest-qunit-intro' ) - ->params( 'https://www.mediawiki.org/wiki/Manual:JavaScript_unit_testing' ) - ->parseAsBlock(); - $baseHtml = <<
HTML; - $out->addHtml( $this->wrapSummaryHtml( $summary ) . $baseHtml ); + $out->addHtml( $this->getSummaryHtml() . $baseHtml ); // The testrunner configures QUnit and essentially depends on it. However, test suites // are reusable in environments that preload QUnit (or a compatibility interface to @@ -249,10 +256,12 @@ HTML; ); $head = trim( $styles['html'] . $scripts['html'] ); + $summary = $this->getSummaryHtml(); $html = << QUnit $head +$summary
HTML; $html .= "\n" . Html::linkedScript( $url ); -- 2.20.1