aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/parserTests.inc
diff options
context:
space:
mode:
authorBrion Vibber <brion@users.mediawiki.org>2006-06-01 04:00:41 +0000
committerBrion Vibber <brion@users.mediawiki.org>2006-06-01 04:00:41 +0000
commit3c04a042b40d116d7e6c7f281a15d241a1d1420d (patch)
tree7d8b078ad2e1103e17c4333529b0090212aaab5a /maintenance/parserTests.inc
parentded981228424c5315eb55be175b4df6593bac412 (diff)
downloadmediawikicore-3c04a042b40d116d7e6c7f281a15d241a1d1420d.tar.gz
mediawikicore-3c04a042b40d116d7e6c7f281a15d241a1d1420d.zip
* parserTests.php accepts a --file parameter to run an alternate test sutie
* parser tests can now test extensions using !!hooks sections
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/14507
Diffstat (limited to 'maintenance/parserTests.inc')
-rw-r--r--maintenance/parserTests.inc35
1 files changed, 34 insertions, 1 deletions
diff --git a/maintenance/parserTests.inc b/maintenance/parserTests.inc
index 77d601a7d25c..9c98a6113a62 100644
--- a/maintenance/parserTests.inc
+++ b/maintenance/parserTests.inc
@@ -92,6 +92,8 @@ class ParserTest {
# Matches anything
$this->regex = '';
}
+
+ $this->hooks = array();
}
/**
@@ -146,6 +148,20 @@ class ParserTest {
$section = null;
continue;
}
+ if( $section == 'endhooks' ) {
+ if( !isset( $data['hooks'] ) ) {
+ wfDie( "'endhooks' without 'hooks' at line $n\n" );
+ }
+ foreach( explode( "\n", $data['hooks'] ) as $line ) {
+ $line = trim( $line );
+ if( $line ) {
+ $this->requireHook( $line );
+ }
+ }
+ $data = array();
+ $section = null;
+ continue;
+ }
if( $section == 'end' ) {
if( !isset( $data['test'] ) ) {
wfDie( "'end' without 'test' at line $n\n" );
@@ -242,6 +258,9 @@ class ParserTest {
$noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts );
$parser =& new Parser();
+ foreach( $this->hooks as $tag => $callback ) {
+ $parser->setHook( $tag, $callback );
+ }
wfRunHooks( 'ParserTestParser', array( &$parser ) );
$title =& Title::makeTitle( NS_MAIN, $titleText );
@@ -659,7 +678,6 @@ class ParserTest {
* @param string $name the title, including any prefix
* @param string $text the article text
* @param int $line the input line number, for reporting errors
- * @static
* @private
*/
function addArticle($name, $text, $line) {
@@ -678,6 +696,21 @@ class ParserTest {
$art->insertNewArticle($text, '', false, false );
$this->teardownGlobals();
}
+
+ /**
+ * 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 requireHook( $name ) {
+ global $wgParser;
+ if( isset( $wgParser->mTagHooks[$name] ) ) {
+ $this->hooks[$name] = $wgParser->mTagHooks[$name];
+ } else {
+ wfDie( "This test suite requires the '$name' hook extension.\n" );
+ }
+ }
/*
* Run the "tidy" command on text if the $wgUseTidy