JSTesting: make sure wrapSummaryHtml is given a valid state
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 4 Jan 2012 10:31:02 +0000 (10:31 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 4 Jan 2012 10:31:02 +0000 (10:31 +0000)
* wrapSummaryHTML() now really need one of three states or an exception
  is thrown.
* Moved a parameter incorrectly passed to addHtml() up to the previous
  wrapSummaryHtml() code. Per CR on r107919

includes/specials/SpecialJavaScriptTest.php

index d19eb8e..c971949 100644 (file)
@@ -58,8 +58,10 @@ class SpecialJavaScriptTest extends SpecialPage {
                        $summary = $this->wrapSummaryHtml( '<p class="error">'
                                . wfMsg( 'javascripttest-pagetext-unknownframework', $par )
                                . '</p>'
-                               . $this->getFrameworkListHtml() );
-                       $out->addHtml( $summary, 'unknownframework' );
+                               . $this->getFrameworkListHtml(),
+                               'unknownframework'
+                       );
+                       $out->addHtml( $summary );
                }
        }
 
@@ -84,10 +86,19 @@ class SpecialJavaScriptTest extends SpecialPage {
 
        /**
         * Function to wrap the summary.
+        * It must be given a valid state as a second parameter or an exception will
+        * be thrown.
         * @param $html String: The raw HTML.
         * @param $state String: State, one of 'noframework', 'unknownframework' or 'frameworkfound'
         */
-       private function wrapSummaryHtml( $html = '', $state ) {
+       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) . '".'
+                       );
+               }
                return "<div id=\"mw-javascripttest-summary\" class=\"mw-javascripttest-$state\">$html</div>";
        }