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['disabled'])) {
37 if( !isset( $data['test'] ) ) {
38 die( "'end' without 'test' at line $n\n" );
40 if( !isset( $data['input'] ) ) {
41 die( "'end' without 'input' at line $n\n" );
43 if( !isset( $data['result'] ) ) {
44 die( "'end' without 'result' at line $n\n" );
47 rtrim( $data['test'] ),
48 rtrim( $data['input'] ),
49 rtrim( $data['result'] ) ) ) {
61 $data[$section] .= $line;
65 $ratio = IntVal( 100.0 * $success / $total );
66 print "\nPassed $success of $total tests ($ratio%)\n";
71 * @param string $input Wikitext to try rendering
72 * @param string $result Result to output
75 function runTest( $desc, $input, $result ) {
76 print "Running test $desc...";
79 $options =& ParserOptions
::newFromUser( $user );
80 $parser =& new Parser();
81 $title =& Title
::makeTitle( NS_MAIN
, 'Parser_test' );
83 $output =& $parser->parse( $input, $title, $options );
85 $html = $output->getText();
86 # $languageLinks = $output->getLanguageLinks();
87 # $categoryLinks = $output->getCategoryLinks();
89 $op = new OutputPage();
90 $op->replaceLinkHolders($html);
92 if( $result == rtrim( $html ) ) {
93 return $this->showSuccess( $desc );
95 return $this->showFailure( $desc, $result, $html );
99 function showSuccess( $desc ) {
104 function showFailure( $desc, $result, $html ) {
106 print "!! Expected:\n$result\n";
107 print "!! Received:\n$html\n!!\n";
112 $tester =& new ParserTest();
113 $tester->runTestsFromFile( 'maintenance/parserTests.txt' );