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 ParserTestRunner|ParserIntegrationTest $parserTest
54 public function unleash( &$parserTest ) {
55 if ( !( $parserTest instanceof ParserTestRunner
56 ||
$parserTest instanceof ParserIntegrationTest
)
58 throw new MWException( __METHOD__
. " must be passed an instance of " .
59 "ParserTestRunner or ParserIntegrationTest classes\n" );
62 # Trigger delayed hooks. Any failure will make us abort
63 foreach ( $this->hooks
as $hook ) {
64 $ret = $parserTest->requireHook( $hook );
70 # Trigger delayed function hooks. Any failure will make us abort
71 foreach ( $this->fnHooks
as $fnHook ) {
72 $ret = $parserTest->requireFunctionHook( $fnHook );
78 # Trigger delayed transparent hooks. Any failure will make us abort
79 foreach ( $this->transparentHooks
as $hook ) {
80 $ret = $parserTest->requireTransparentHook( $hook );
86 # Delayed execution was successful.
91 * Similar to ParserTestRunner object but does not run anything
92 * Use unleash() to really execute the hook
95 public function requireHook( $hook ) {
96 $this->hooks
[] = $hook;
100 * Similar to ParserTestRunner object but does not run anything
101 * Use unleash() to really execute the hook function
102 * @param string $fnHook
104 public function requireFunctionHook( $fnHook ) {
105 $this->fnHooks
[] = $fnHook;
109 * Similar to ParserTestRunner object but does not run anything
110 * Use unleash() to really execute the hook function
111 * @param string $hook
113 public function requireTransparentHook( $hook ) {
114 $this->transparentHooks
[] = $hook;