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 (is_null($section) && preg_match('/^#/', $line)) {
32 if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
33 $section = strtolower( $matches[1] );
34 if( $section == 'end' ) {
35 if( !isset( $data['test'] ) ) {
36 die( "'end' without 'test' at line $n\n" );
38 if( !isset( $data['input'] ) ) {
39 die( "'end' without 'input' at line $n\n" );
41 if( !isset( $data['result'] ) ) {
42 die( "'end' without 'result' at line $n\n" );
45 rtrim( $data['test'] ),
46 rtrim( $data['input'] ),
47 rtrim( $data['result'] ) ) ) {
59 $data[$section] .= $line;
63 $ratio = IntVal( 100.0 * $success / $total );
64 print "\nPassed $success of $total tests ($ratio%)\n";
69 * @param string $input Wikitext to try rendering
70 * @param string $result Result to output
73 function runTest( $desc, $input, $result ) {
74 print "Running test $desc...";
77 $options =& ParserOptions
::newFromUser( $user );
78 $parser =& new Parser();
79 $title =& Title
::makeTitle( NS_MAIN
, 'Parser_test' );
81 $output =& $parser->parse( $input, $title, $options );
83 $html = $output->getText();
84 # $languageLinks = $output->getLanguageLinks();
85 # $categoryLinks = $output->getCategoryLinks();
87 if( $result == rtrim( $html ) ) {
88 return $this->showSuccess( $desc );
90 return $this->showFailure( $desc, $result, $html );
94 function showSuccess( $desc ) {
99 function showFailure( $desc, $result, $html ) {
101 print "!! Expected:\n$result\n";
102 print "!! Received:\n$html\n!!\n";
107 $tester =& new ParserTest();
108 $tester->runTestsFromFile( 'maintenance/parserTests.txt' );