r108360 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108359‎ | r108360 | r108361 >
Date:17:32, 8 January 2012
Author:demon
Status:ok
Tags:
Comment:
Followup r108358, bring back DelayedParserTest
Modified paths:
  • /trunk/phase3/tests/testHelpers.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/testHelpers.inc
@@ -226,3 +226,72 @@
227227 return true;
228228 }
229229 }
 230+
 231+/**
 232+ * A class to delay execution of a parser test hooks.
 233+ */
 234+class DelayedParserTest {
 235+
 236+ /** Initialized on construction */
 237+ private $hooks;
 238+ private $fnHooks;
 239+
 240+ public function __construct() {
 241+ $this->reset();
 242+ }
 243+
 244+ /**
 245+ * Init/reset or forgot about the current delayed test.
 246+ * Call to this will erase any hooks function that were pending.
 247+ */
 248+ public function reset() {
 249+ $this->hooks = array();
 250+ $this->fnHooks = array();
 251+ }
 252+
 253+ /**
 254+ * Called whenever we actually want to run the hook.
 255+ * Should be the case if we found the parserTest is not disabled
 256+ */
 257+ public function unleash( &$parserTest ) {
 258+ if( !($parserTest instanceof ParserTest || $parserTest instanceof NewParserTest
 259+ ) ) {
 260+ throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or NewParserTest classes\n" );
 261+ }
 262+
 263+ # Trigger delayed hooks. Any failure will make us abort
 264+ foreach( $this->hooks as $hook ) {
 265+ $ret = $parserTest->requireHook( $hook );
 266+ if( !$ret ) {
 267+ return false;
 268+ }
 269+ }
 270+
 271+ # Trigger delayed function hooks. Any failure will make us abort
 272+ foreach( $this->fnHooks as $fnHook ) {
 273+ $ret = $parserTest->requireFunctionHook( $fnHook );
 274+ if( !$ret ) {
 275+ return false;
 276+ }
 277+ }
 278+
 279+ # Delayed execution was successful.
 280+ return true;
 281+ }
 282+
 283+ /**
 284+ * Similar to ParserTest object but does not run anything
 285+ * Use unleash() to really execute the hook
 286+ */
 287+ public function requireHook( $hook ) {
 288+ $this->hooks[] = $hook;
 289+ }
 290+ /**
 291+ * Similar to ParserTest object but does not run anything
 292+ * Use unleash() to really execute the hook function
 293+ */
 294+ public function requireFunctionHook( $fnHook ) {
 295+ $this->fnHooks[] = $fnHook;
 296+ }
 297+
 298+}
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108358* Drop old parserTests.php way of running parser tests. You can run parser te...demon17:28, 8 January 2012

Status & tagging log