4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
24 * A class to delay execution of a parser test hooks.
26 class DelayedParserTest
{
28 /** Initialized on construction */
31 private $transparentHooks;
33 public function __construct() {
38 * Init/reset or forgot about the current delayed test.
39 * Call to this will erase any hooks function that were pending.
41 public function reset() {
44 $this->transparentHooks
= [];
48 * Called whenever we actually want to run the hook.
49 * Should be the case if we found the parserTest is not disabled
50 * @param ParserTest|NewParserTest $parserTest
54 public function unleash( &$parserTest ) {
55 if ( !( $parserTest instanceof ParserTest ||
$parserTest instanceof NewParserTest
) ) {
56 throw new MWException( __METHOD__
. " must be passed an instance of ParserTest or "
57 . "NewParserTest classes\n" );
60 # Trigger delayed hooks. Any failure will make us abort
61 foreach ( $this->hooks
as $hook ) {
62 $ret = $parserTest->requireHook( $hook );
68 # Trigger delayed function hooks. Any failure will make us abort
69 foreach ( $this->fnHooks
as $fnHook ) {
70 $ret = $parserTest->requireFunctionHook( $fnHook );
76 # Trigger delayed transparent hooks. Any failure will make us abort
77 foreach ( $this->transparentHooks
as $hook ) {
78 $ret = $parserTest->requireTransparentHook( $hook );
84 # Delayed execution was successful.
89 * Similar to ParserTest object but does not run anything
90 * Use unleash() to really execute the hook
93 public function requireHook( $hook ) {
94 $this->hooks
[] = $hook;
98 * Similar to ParserTest object but does not run anything
99 * Use unleash() to really execute the hook function
100 * @param string $fnHook
102 public function requireFunctionHook( $fnHook ) {
103 $this->fnHooks
[] = $fnHook;
107 * Similar to ParserTest object but does not run anything
108 * Use unleash() to really execute the hook function
109 * @param string $hook
111 public function requireTransparentHook( $hook ) {
112 $this->transparentHooks
[] = $hook;