allow simple variables in expected test results; use tidy on expected result when
authorWil Mahan <wmahan@users.mediawiki.org>
Thu, 23 Sep 2004 00:30:28 +0000 (00:30 +0000)
committerWil Mahan <wmahan@users.mediawiki.org>
Thu, 23 Sep 2004 00:30:28 +0000 (00:30 +0000)
$wgUseTidy is enabled, which makes it possible to disregard cosmetic formatting
discrepancies

maintenance/parserTests.php

index 3fdd3f2..5e70ca0 100644 (file)
@@ -46,7 +46,7 @@ class ParserTest {
                                        if( $this->runTest(
                                                rtrim( $data['test'] ),
                                                rtrim( $data['input'] ),
-                                               rtrim( $data['result'] ) ) ) {
+                                               $this->resultTransform(rtrim( $data['result'] ) ) ) ) {
                                                $success++;
                                        }
                                        $total++;
@@ -67,6 +67,19 @@ class ParserTest {
                }
        }
 
+       /**
+        * Substitute simple variables to allow for slightly more
+        * sophisticated tests.
+        * @access private
+        */
+       function resultTransform($text) {
+               $rep = array (
+                       '__SCRIPT__' => $GLOBALS['wgScript']
+               );
+               $text = str_replace(array_keys($rep), array_values($rep), $text);
+               return $text;
+       }
+
        /**
         * @param string $input Wikitext to try rendering
         * @param string $result Result to output
@@ -88,8 +101,17 @@ class ParserTest {
 
                $op = new OutputPage();
                $op->replaceLinkHolders($html);
+
+               global $wgUseTidy;
+               if ($wgUseTidy) {
+                       # Using Parser here is probably theoretically
+                       # wrong, because we shouldn't use Parser to
+                       # validate itself, but this should be safe
+                       # in practice.
+                       $result = Parser::tidy($result);
+               }
                
-               if( $result == rtrim( $html ) ) {
+               if( rtrim($result) === rtrim($html) ) {
                        return $this->showSuccess( $desc );
                } else {
                        return $this->showFailure( $desc, $result, $html );