* (bug 7801) Add support for parser function hooks in parser tests
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 4 Nov 2006 18:00:57 +0000 (18:00 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 4 Nov 2006 18:00:57 +0000 (18:00 +0000)
patch by Steve Sanbeg:
http://bugzilla.wikimedia.org/attachment.cgi?id=2628&action=view

RELEASE-NOTES
maintenance/parserTests.inc

index f664bb1..ffe476b 100644 (file)
@@ -140,6 +140,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 7774) MATH: aded more amstex functions
 * (bug 1182) MATH: fixed inconsistent rendering of upper case Greek letters in TeX
 * Fix regression in streaming page dump generation
+* (bug 7801) Add support for parser function hooks in parser tests
 
 
 == Languages updated ==
index b01190a..c34ba20 100644 (file)
@@ -99,6 +99,7 @@ class ParserTest {
                }
                
                $this->hooks = array();
+               $this->functionHooks = array();
        }
 
        /**
@@ -167,6 +168,20 @@ class ParserTest {
                                        $section = null;
                                        continue;
                                }
+                               if( $section == 'endfunctionhooks' ) {
+                                       if( !isset( $data['functionhooks'] ) ) {
+                                               wfDie( "'endfunctionhooks' without 'functionhooks' at line $n\n" );
+                                       }
+                                       foreach( explode( "\n", $data['functionhooks'] ) as $line ) {
+                                               $line = trim( $line );
+                                               if( $line ) {
+                                                       $this->requireFunctionHook( $line );
+                                               }
+                                       }
+                                       $data = array();
+                                       $section = null;
+                                       continue;
+                               }
                                if( $section == 'end' ) {
                                        if( !isset( $data['test'] ) ) {
                                                wfDie( "'end' without 'test' at line $n\n" );
@@ -264,6 +279,9 @@ class ParserTest {
                foreach( $this->hooks as $tag => $callback ) {
                        $parser->setHook( $tag, $callback );
                }
+               foreach( $this->functionHooks as $tag => $callback ) {
+                       $parser->setFunctionHook( $tag, $callback );
+               }
                wfRunHooks( 'ParserTestParser', array( &$parser ) );
                
                $title =& Title::makeTitle( NS_MAIN, $titleText );
@@ -729,6 +747,22 @@ class ParserTest {
                }
        }
 
+       
+       /**
+        * Steal a callback function from the primary parser, save it for
+        * application to our scary parser. If the hook is not installed,
+        * die a painful dead to warn the others.
+        * @param string $name
+        */
+       private function requireFunctionHook( $name ) {
+               global $wgParser;
+               if( isset( $wgParser->mFunctionHooks[$name] ) ) {
+                       $this->functionHooks[$name] = $wgParser->mFunctionHooks[$name];
+               } else {
+                       wfDie( "This test suite requires the '$name' function hook extension.\n" );
+               }
+       }
+
        /*
         * Run the "tidy" command on text if the $wgUseTidy
         * global is true