$this->hooks = array();
$this->functionHooks = array();
+ $this->transparentHooks = array();
self::setUp();
}
$parser->setFunctionHook( $tag, $callback, $flags );
}
+ foreach ( $this->transparentHooks as $tag => $callback ) {
+ $parser->setTransparentTagHook( $tag, $callback );
+ }
+
wfRunHooks( 'ParserTestParser', array( &$parser ) );
return $parser;
return true;
}
+ /**
+ * Steal a callback function from the primary parser, save it for
+ * application to our scary parser. If the hook is not installed,
+ * abort processing of this file.
+ *
+ * @param string $name
+ * @return bool True if function hook is present
+ */
+ public function requireTransparentHook( $name ) {
+ global $wgParser;
+
+ $wgParser->firstCallInit(); // make sure hooks are loaded.
+
+ if ( isset( $wgParser->mTransparentTagHooks[$name] ) ) {
+ $this->transparentHooks[$name] = $wgParser->mTransparentTagHooks[$name];
+ } else {
+ echo " This test suite requires the '$name' transparent hook extension, skipping.\n";
+ return false;
+ }
+
+ return true;
+ }
+
/**
* Run the "tidy" command on text if the $wgUseTidy
* global is true
public $savedGlobals = array();
public $hooks = array();
public $functionHooks = array();
+ public $transparentHooks = array();
//Fuzz test
public $maxFuzzTestLength = 300;
return isset( $wgParser->mFunctionHooks[$name] );
}
+ public function requireTransparentHook( $name ) {
+ global $wgParser;
+ $wgParser->firstCallInit(); // make sure hooks are loaded.
+ return isset( $wgParser->mTransparentTagHooks[$name] );
+ }
+
//Various "cleanup" functions
/**
continue;
}
+ if ( $this->section == 'endtransparenthooks' ) {
+ $this->checkSection( 'transparenthooks' );
+
+ foreach ( explode( "\n", $this->sectionData['transparenthooks'] ) as $line ) {
+ $line = trim( $line );
+
+ if ( $line ) {
+ $delayedParserTest->requireTransparentHook( $line );
+ }
+ }
+
+ $this->clearSection();
+
+ continue;
+ }
+
if ( $this->section == 'end' ) {
$this->checkSection( 'test' );
// "input" and "result" are old section names allowed
/** Initialized on construction */
private $hooks;
private $fnHooks;
+ private $transparentHooks;
public function __construct() {
$this->reset();
public function reset() {
$this->hooks = array();
$this->fnHooks = array();
+ $this->transparentHooks = array();
}
/**
}
}
+ # Trigger delayed transparent hooks. Any failure will make us abort
+ foreach ( $this->transparentHooks as $hook ) {
+ $ret = $parserTest->requireTransparentHook( $hook );
+ if ( !$ret ) {
+ return false;
+ }
+ }
+
# Delayed execution was successful.
return true;
}
$this->fnHooks[] = $fnHook;
}
+ /**
+ * Similar to ParserTest object but does not run anything
+ * Use unleash() to really execute the hook function
+ * @param string $fnHook
+ */
+ public function requireTransparentHook( $hook ) {
+ $this->transparentHooks[] = $hook;
+ }
+
}
/**