From: Chad Horohoe Date: Sun, 8 Jan 2012 17:32:39 +0000 (+0000) Subject: Followup r108358, bring back DelayedParserTest X-Git-Tag: 1.31.0-rc.0~25425 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=23b605084cf6f1f70800eb09116b98f3fda7f4e5;p=lhc%2Fweb%2Fwiklou.git Followup r108358, bring back DelayedParserTest --- diff --git a/tests/testHelpers.inc b/tests/testHelpers.inc index f6611360dd..94168ab077 100644 --- a/tests/testHelpers.inc +++ b/tests/testHelpers.inc @@ -226,3 +226,72 @@ class TestFileIterator implements Iterator { return true; } } + +/** + * A class to delay execution of a parser test hooks. + */ +class DelayedParserTest { + + /** Initialized on construction */ + private $hooks; + private $fnHooks; + + public function __construct() { + $this->reset(); + } + + /** + * Init/reset or forgot about the current delayed test. + * Call to this will erase any hooks function that were pending. + */ + public function reset() { + $this->hooks = array(); + $this->fnHooks = array(); + } + + /** + * Called whenever we actually want to run the hook. + * Should be the case if we found the parserTest is not disabled + */ + 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" ); + } + + # Trigger delayed hooks. Any failure will make us abort + foreach( $this->hooks as $hook ) { + $ret = $parserTest->requireHook( $hook ); + if( !$ret ) { + return false; + } + } + + # Trigger delayed function hooks. Any failure will make us abort + foreach( $this->fnHooks as $fnHook ) { + $ret = $parserTest->requireFunctionHook( $fnHook ); + if( !$ret ) { + return false; + } + } + + # Delayed execution was successful. + return true; + } + + /** + * Similar to ParserTest object but does not run anything + * Use unleash() to really execute the hook + */ + public function requireHook( $hook ) { + $this->hooks[] = $hook; + } + /** + * Similar to ParserTest object but does not run anything + * Use unleash() to really execute the hook function + */ + public function requireFunctionHook( $fnHook ) { + $this->fnHooks[] = $fnHook; + } + +} \ No newline at end of file