resourceloader: Wrap only=script responses in "if(window.mw)"
[lhc/web/wiklou.git] / tests / testHelpers.inc
index d2e7f6e..717c5f3 100644 (file)
@@ -318,7 +318,7 @@ class DbTestRecorder extends DbTestPreviewer {
                        array(
                                'tr_date' => $this->db->timestamp(),
                                'tr_mw_version' => $this->version,
-                               'tr_php_version' => phpversion(),
+                               'tr_php_version' => PHP_VERSION,
                                'tr_db_version' => $this->db->getServerVersion(),
                                'tr_uname' => php_uname()
                        ),
@@ -352,7 +352,11 @@ class DbTestRecorder extends DbTestPreviewer {
 class TestFileIterator implements Iterator {
        private $file;
        private $fh;
-       private $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
+       /**
+        * @var ParserTest|MediaWikiParserTest An instance of ParserTest (parserTests.php)
+        *  or MediaWikiParserTest (phpunit)
+        */
+       private $parserTest;
        private $index = 0;
        private $test;
        private $section = null;
@@ -426,7 +430,9 @@ class TestFileIterator implements Iterator {
                                        $this->checkSection( 'text' );
                                        $this->checkSection( 'article' );
 
-                                       $this->parserTest->addArticle( ParserTest::chomp( $this->sectionData['article'] ), $this->sectionData['text'], $this->lineNum );
+                                       $this->parserTest->addArticle(
+                                               ParserTest::chomp( $this->sectionData['article'] ),
+                                               $this->sectionData['text'], $this->lineNum );
 
                                        $this->clearSection();
 
@@ -497,8 +503,10 @@ class TestFileIterator implements Iterator {
                                        }
 
                                        if ( $input == false || $result == false ||
-                                               ( ( preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] ) && !$this->parserTest->runDisabled )
-                                               || ( preg_match( '/\\bparsoid\\b/i', $this->sectionData['options'] ) && $result != 'html/php' && !$this->parserTest->runParsoid )
+                                               ( ( preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] )
+                                                       && !$this->parserTest->runDisabled )
+                                               || ( preg_match( '/\\bparsoid\\b/i', $this->sectionData['options'] )
+                                                       && $result != 'html/php' && !$this->parserTest->runParsoid )
                                                || !preg_match( "/" . $this->parserTest->regex . "/i", $this->sectionData['test'] ) )
                                        ) {
                                                # disabled test
@@ -520,8 +528,8 @@ class TestFileIterator implements Iterator {
 
                                        $this->test = array(
                                                'test' => ParserTest::chomp( $this->sectionData['test'] ),
-                                               'input' => ParserTest::chomp( $this->sectionData[ $input ] ),
-                                               'result' => ParserTest::chomp( $this->sectionData[ $result ] ),
+                                               'input' => ParserTest::chomp( $this->sectionData[$input] ),
+                                               'result' => ParserTest::chomp( $this->sectionData[$result] ),
                                                'options' => ParserTest::chomp( $this->sectionData['options'] ),
                                                'config' => ParserTest::chomp( $this->sectionData['config'] ),
                                        );
@@ -530,7 +538,8 @@ class TestFileIterator implements Iterator {
                                }
 
                                if ( isset( $this->sectionData[$this->section] ) ) {
-                                       throw new MWException( "duplicate section '$this->section' at line {$this->lineNum} of $this->file\n" );
+                                       throw new MWException( "duplicate section '$this->section' "
+                                               . "at line {$this->lineNum} of $this->file\n" );
                                }
 
                                $this->sectionData[$this->section] = '';
@@ -579,7 +588,7 @@ class TestFileIterator implements Iterator {
 
                $data = $this->sectionData;
                $tokens = array_filter( $tokens, function ( $token ) use ( $data ) {
-                       return isset( $data[ $token ] );
+                       return isset( $data[$token] );
                } );
 
                if ( count( $tokens ) == 0 ) {
@@ -605,7 +614,7 @@ class TestFileIterator implements Iterator {
                }
 
                $tokens = array_values( $tokens );
-               return $tokens[ 0 ];
+               return $tokens[0];
        }
 }
 
@@ -640,7 +649,8 @@ class DelayedParserTest {
         */
        public function unleash( &$parserTest ) {
                if ( !( $parserTest instanceof ParserTest || $parserTest instanceof NewParserTest )     ) {
-                       throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or NewParserTest classes\n" );
+                       throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or "
+                               . "NewParserTest classes\n" );
                }
 
                # Trigger delayed hooks. Any failure will make us abort