array(
'tr_date' => $this->db->timestamp(),
'tr_mw_version' => $this->version,
- 'tr_php_version' => phpversion(),
+ 'tr_php_version' => PHP_VERSION,
'tr_db_version' => $this->db->getServerVersion(),
'tr_uname' => php_uname()
),
class TestFileIterator implements Iterator {
private $file;
private $fh;
- private $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
+ /**
+ * @var ParserTest|MediaWikiParserTest An instance of ParserTest (parserTests.php)
+ * or MediaWikiParserTest (phpunit)
+ */
+ private $parserTest;
private $index = 0;
private $test;
private $section = null;
$this->checkSection( 'text' );
$this->checkSection( 'article' );
- $this->parserTest->addArticle( ParserTest::chomp( $this->sectionData['article'] ), $this->sectionData['text'], $this->lineNum );
+ $this->parserTest->addArticle(
+ ParserTest::chomp( $this->sectionData['article'] ),
+ $this->sectionData['text'], $this->lineNum );
$this->clearSection();
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
}
if ( $input == false || $result == false ||
- ( ( preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] ) && !$this->parserTest->runDisabled )
- || ( preg_match( '/\\bparsoid\\b/i', $this->sectionData['options'] ) && $result != 'html/php' && !$this->parserTest->runParsoid )
+ ( ( preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] )
+ && !$this->parserTest->runDisabled )
+ || ( preg_match( '/\\bparsoid\\b/i', $this->sectionData['options'] )
+ && $result != 'html/php' && !$this->parserTest->runParsoid )
|| !preg_match( "/" . $this->parserTest->regex . "/i", $this->sectionData['test'] ) )
) {
# disabled test
$this->test = array(
'test' => ParserTest::chomp( $this->sectionData['test'] ),
- 'input' => ParserTest::chomp( $this->sectionData[ $input ] ),
- 'result' => ParserTest::chomp( $this->sectionData[ $result ] ),
+ 'input' => ParserTest::chomp( $this->sectionData[$input] ),
+ 'result' => ParserTest::chomp( $this->sectionData[$result] ),
'options' => ParserTest::chomp( $this->sectionData['options'] ),
'config' => ParserTest::chomp( $this->sectionData['config'] ),
);
}
if ( isset( $this->sectionData[$this->section] ) ) {
- throw new MWException( "duplicate section '$this->section' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "duplicate section '$this->section' "
+ . "at line {$this->lineNum} of $this->file\n" );
}
$this->sectionData[$this->section] = '';
$data = $this->sectionData;
$tokens = array_filter( $tokens, function ( $token ) use ( $data ) {
- return isset( $data[ $token ] );
+ return isset( $data[$token] );
} );
if ( count( $tokens ) == 0 ) {
}
$tokens = array_values( $tokens );
- return $tokens[ 0 ];
+ return $tokens[0];
}
}
/** 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();
}
/**
*/
public function unleash( &$parserTest ) {
if ( !( $parserTest instanceof ParserTest || $parserTest instanceof NewParserTest ) ) {
- throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or NewParserTest classes\n" );
+ throw new MWException( __METHOD__ . " must be passed an instance of ParserTest or "
+ . "NewParserTest classes\n" );
}
# Trigger delayed hooks. Any failure will make us abort
}
}
+ # 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;
+ }
+
}
/**