Index: trunk/phase3/tests/testHelpers.inc |
— | — | @@ -226,3 +226,72 @@ |
227 | 227 | return true; |
228 | 228 | } |
229 | 229 | } |
| 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 |