Merge "Add support for testing transparent tags"

This commit is contained in:
jenkins-bot 2014-06-23 22:53:15 +00:00 committed by Gerrit Code Review
commit 66ce50f591
3 changed files with 70 additions and 0 deletions

View file

@ -145,6 +145,7 @@ class ParserTest {
$this->hooks = array();
$this->functionHooks = array();
$this->transparentHooks = array();
self::setUp();
}
@ -528,6 +529,10 @@ class ParserTest {
$parser->setFunctionHook( $tag, $callback, $flags );
}
foreach ( $this->transparentHooks as $tag => $callback ) {
$parser->setTransparentTagHook( $tag, $callback );
}
wfRunHooks( 'ParserTestParser', array( &$parser ) );
return $parser;
@ -1523,6 +1528,29 @@ class ParserTest {
return true;
}
/**
* Steal a callback function from the primary parser, save it for
* application to our scary parser. If the hook is not installed,
* abort processing of this file.
*
* @param string $name
* @return bool True if function hook is present
*/
public function requireTransparentHook( $name ) {
global $wgParser;
$wgParser->firstCallInit(); // make sure hooks are loaded.
if ( isset( $wgParser->mTransparentTagHooks[$name] ) ) {
$this->transparentHooks[$name] = $wgParser->mTransparentTagHooks[$name];
} else {
echo " This test suite requires the '$name' transparent hook extension, skipping.\n";
return false;
}
return true;
}
/**
* Run the "tidy" command on text if the $wgUseTidy
* global is true

View file

@ -25,6 +25,7 @@ class NewParserTest extends MediaWikiTestCase {
public $savedGlobals = array();
public $hooks = array();
public $functionHooks = array();
public $transparentHooks = array();
//Fuzz test
public $maxFuzzTestLength = 300;
@ -945,6 +946,12 @@ class NewParserTest extends MediaWikiTestCase {
return isset( $wgParser->mFunctionHooks[$name] );
}
public function requireTransparentHook( $name ) {
global $wgParser;
$wgParser->firstCallInit(); // make sure hooks are loaded.
return isset( $wgParser->mTransparentTagHooks[$name] );
}
//Various "cleanup" functions
/**

View file

@ -465,6 +465,22 @@ class TestFileIterator implements Iterator {
continue;
}
if ( $this->section == 'endtransparenthooks' ) {
$this->checkSection( 'transparenthooks' );
foreach ( explode( "\n", $this->sectionData['transparenthooks'] ) as $line ) {
$line = trim( $line );
if ( $line ) {
$delayedParserTest->requireTransparentHook( $line );
}
}
$this->clearSection();
continue;
}
if ( $this->section == 'end' ) {
$this->checkSection( 'test' );
// "input" and "result" are old section names allowed
@ -601,6 +617,7 @@ class DelayedParserTest {
/** Initialized on construction */
private $hooks;
private $fnHooks;
private $transparentHooks;
public function __construct() {
$this->reset();
@ -613,6 +630,7 @@ class DelayedParserTest {
public function reset() {
$this->hooks = array();
$this->fnHooks = array();
$this->transparentHooks = array();
}
/**
@ -641,6 +659,14 @@ class DelayedParserTest {
}
}
# Trigger delayed transparent hooks. Any failure will make us abort
foreach ( $this->transparentHooks as $hook ) {
$ret = $parserTest->requireTransparentHook( $hook );
if ( !$ret ) {
return false;
}
}
# Delayed execution was successful.
return true;
}
@ -663,6 +689,15 @@ class DelayedParserTest {
$this->fnHooks[] = $fnHook;
}
/**
* Similar to ParserTest object but does not run anything
* Use unleash() to really execute the hook function
* @param string $fnHook
*/
public function requireTransparentHook( $hook ) {
$this->transparentHooks[] = $hook;
}
}
/**