3 class ParserTestFileIterator
implements Iterator
{
7 protected $parserTest; /* An instance of ParserTest (parserTests.php) or MediaWikiParserTest (phpunit) */
13 function __construct( $file, $parserTest ) {
17 $this->fh
= fopen( $this->file
, "rt" );
20 wfDie( "Couldn't open file '$file'\n" );
23 $this->parserTest
= $parserTest;
24 //$this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
26 $this->lineNum
= $this->index
= 0;
30 if ( fseek( $this->fh
, 0 ) ) {
31 wfDie( "Couldn't fseek to the start of '$this->file'\n" );
51 if ( $this->readNextTest() ) {
60 return $this->eof
!= true;
63 function readNextTest() {
67 while ( false !== ( $line = fgets( $this->fh
) ) ) {
71 if ( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
72 $section = strtolower( $matches[1] );
74 if ( $section == 'endarticle' ) {
75 if ( !isset( $data['text'] ) ) {
76 wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
79 if ( !isset( $data['article'] ) ) {
80 wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
83 $this->parserTest
->addArticle( $this->parserTest
->removeEndingNewline( $data['article'] ), $data['text'], $this->lineNum
);
92 if ( $section == 'endhooks' ) {
93 if ( !isset( $data['hooks'] ) ) {
94 wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
97 foreach ( explode( "\n", $data['hooks'] ) as $line ) {
98 $line = trim( $line );
101 if ( !$this->parserTest
->requireHook( $line ) ) {
113 if ( $section == 'endfunctionhooks' ) {
114 if ( !isset( $data['functionhooks'] ) ) {
115 wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
118 foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
119 $line = trim( $line );
122 if ( !$this->parserTest
->requireFunctionHook( $line ) ) {
134 if ( $section == 'end' ) {
135 if ( !isset( $data['test'] ) ) {
136 wfDie( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
139 if ( !isset( $data['input'] ) ) {
140 wfDie( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
143 if ( !isset( $data['result'] ) ) {
144 wfDie( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
147 if ( !isset( $data['options'] ) ) {
148 $data['options'] = '';
151 if ( !isset( $data['config'] ) )
152 $data['config'] = '';
154 if ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest
->runDisabled
)
155 ||
!preg_match( "/" . $this->parserTest
->regex
. "/i", $data['test'] ) ) {
165 if ( preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
166 # don't run math tests if $wgUseTeX is set to false in LocalSettings
174 'test' => $this->parserTest
->removeEndingNewline( $data['test'] ),
175 'input' => $this->parserTest
->removeEndingNewline( $data['input'] ),
176 'result' => $this->parserTest
->removeEndingNewline( $data['result'] ),
177 'options' => $this->parserTest
->removeEndingNewline( $data['options'] ),
178 'config' => $this->parserTest
->removeEndingNewline( $data['config'] ) );
183 if ( isset ( $data[$section] ) ) {
184 wfDie( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
187 $data[$section] = '';
193 $data[$section] .= $line;