3 class ParserTestFileIterator
implements Iterator
{
7 protected $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
13 function __construct( $file, $parserTest ) {
15 $this->fh
= fopen( $this->file
, "rt" );
18 wfDie( "Couldn't open file '$file'\n" );
21 $this->parserTest
= $parserTest;
22 //$this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
24 $this->lineNum
= $this->index
= 0;
28 if ( fseek( $this->fh
, 0 ) ) {
29 wfDie( "Couldn't fseek to the start of '$this->file'\n" );
49 if ( $this->readNextTest() ) {
58 return $this->eof
!= true;
61 function readNextTest() {
65 while ( false !== ( $line = fgets( $this->fh
) ) ) {
69 if ( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
70 $section = strtolower( $matches[1] );
72 if ( $section == 'endarticle' ) {
73 if ( !isset( $data['text'] ) ) {
74 wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
77 if ( !isset( $data['article'] ) ) {
78 wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
81 $this->parserTest
->addArticle( $this->parserTest
->removeEndingNewline( $data['article'] ), $data['text'], $this->lineNum
);
90 if ( $section == 'endhooks' ) {
91 if ( !isset( $data['hooks'] ) ) {
92 wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
95 foreach ( explode( "\n", $data['hooks'] ) as $line ) {
96 $line = trim( $line );
99 if ( !$this->parserTest
->requireHook( $line ) ) {
111 if ( $section == 'endfunctionhooks' ) {
112 if ( !isset( $data['functionhooks'] ) ) {
113 wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
116 foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
117 $line = trim( $line );
120 if ( !$this->parserTest
->requireFunctionHook( $line ) ) {
132 if ( $section == 'end' ) {
133 if ( !isset( $data['test'] ) ) {
134 wfDie( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
137 if ( !isset( $data['input'] ) ) {
138 wfDie( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
141 if ( !isset( $data['result'] ) ) {
142 wfDie( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
145 if ( !isset( $data['options'] ) ) {
146 $data['options'] = '';
149 if ( !isset( $data['config'] ) )
150 $data['config'] = '';
152 if ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest
->runDisabled
)
153 ||
!preg_match( "/" . $this->parserTest
->regex
. "/i", $data['test'] ) ) {
163 if ( preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
164 # don't run math tests if $wgUseTeX is set to false in LocalSettings
172 'test' => $this->parserTest
->removeEndingNewline( $data['test'] ),
173 'input' => $this->parserTest
->removeEndingNewline( $data['input'] ),
174 'result' => $this->parserTest
->removeEndingNewline( $data['result'] ),
175 'options' => $this->parserTest
->removeEndingNewline( $data['options'] ),
176 'config' => $this->parserTest
->removeEndingNewline( $data['config'] ) );
181 if ( isset ( $data[$section] ) ) {
182 wfDie( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
185 $data[$section] = '';
191 $data[$section] .= $line;