5 * @subpackage Maintenance
9 require_once( 'commandLine.inc' );
10 include_once( 'InitialiseMessages.inc' );
12 $wgTitle = Title
::newFromText( 'Parser test script' );
15 function runTestsFromFile( $filename ) {
16 $infile = fopen( $filename, 'rt' );
18 die( "Couldn't open parserTests.txt\n" );
26 while( false !== ($line = fgets( $infile ) ) ) {
28 if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
29 $section = strtolower( $matches[1] );
30 if( $section == 'end' ) {
31 if( !isset( $data['test'] ) ) {
32 die( "'end' without 'test' at line $n\n" );
34 if( !isset( $data['input'] ) ) {
35 die( "'end' without 'input' at line $n\n" );
37 if( !isset( $data['result'] ) ) {
38 die( "'end' without 'result' at line $n\n" );
41 rtrim( $data['test'] ),
42 rtrim( $data['input'] ),
43 rtrim( $data['result'] ) ) ) {
55 $data[$section] .= $line;
59 $ratio = IntVal( 100.0 * $success / $total );
60 print "\nPassed $success of $total tests ($ratio%)\n";
65 * @param string $input Wikitext to try rendering
66 * @param string $result Result to output
69 function runTest( $desc, $input, $result ) {
70 print "Running test $desc...";
73 $options =& ParserOptions
::newFromUser( $user );
74 $parser =& new Parser();
75 $title =& Title
::makeTitle( NS_MAIN
, 'Parser_test' );
77 $output =& $parser->parse( $input, $title, $options );
79 $html = $output->getText();
80 # $languageLinks = $output->getLanguageLinks();
81 # $categoryLinks = $output->getCategoryLinks();
83 if( $result == rtrim( $html ) ) {
84 return $this->showSuccess( $desc );
86 return $this->showFailure( $desc, $result, $html );
90 function showSuccess( $desc ) {
95 function showFailure( $desc, $result, $html ) {
97 print "!! Expected:\n$result\n";
98 print "!! Received:\n$html\n!!\n";
103 $tester =& new ParserTest();
104 $tester->runTestsFromFile( 'maintenance/parserTests.txt' );