MediaWiki  REL1_22
MediaWikiParserTest.php
Go to the documentation of this file.
00001 <?php
00002 require_once __DIR__ . '/NewParserTest.php';
00003 
00012 class MediaWikiParserTest {
00013 
00022     const CORE_ONLY = 1;
00024     const NO_CORE = 2;
00026     const WITH_ALL = 3; # CORE_ONLY | NO_CORE
00027 
00053     public static function suite( $flags = self::CORE_ONLY ) {
00054         if ( is_string( $flags ) ) {
00055             $flags = self::CORE_ONLY;
00056         }
00057         global $wgParserTestFiles, $IP;
00058 
00059         $mwTestDir = $IP . '/tests/';
00060 
00061         # Human friendly helpers
00062         $wantsCore = ( $flags & self::CORE_ONLY );
00063         $wantsRest = ( $flags & self::NO_CORE );
00064 
00065         # Will hold the .txt parser test files we will include
00066         $filesToTest = array();
00067 
00068         # Filter out .txt files
00069         foreach ( $wgParserTestFiles as $parserTestFile ) {
00070             $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) );
00071 
00072             if ( $isCore && $wantsCore ) {
00073                 self::debug( "included core parser tests: $parserTestFile" );
00074                 $filesToTest[] = $parserTestFile;
00075             } elseif ( !$isCore && $wantsRest ) {
00076                 self::debug( "included non core parser tests: $parserTestFile" );
00077                 $filesToTest[] = $parserTestFile;
00078             } else {
00079                 self::debug( "skipped parser tests: $parserTestFile" );
00080             }
00081         }
00082         self::debug( 'parser tests files: '
00083             . implode( ' ', $filesToTest ) );
00084 
00085         $suite = new PHPUnit_Framework_TestSuite;
00086         foreach ( $filesToTest as $fileName ) {
00087             $testsName = basename( $fileName, '.txt' );
00088             $escapedFileName = strtr( $fileName, array( "'" => "\\'", '\\' => '\\\\' ) );
00089             /* This used to be ucfirst( basename( dirname( $filename ) ) )
00090              * and then was ucfirst( basename( $filename, '.txt' )
00091              * but that didn't work with names like foo.tests.txt
00092              */
00093             $parserTestClassName = str_replace( '.', '_', ucfirst( $testsName ) );
00094             $parserTestClassDefinition = <<<EOT
00101 class $parserTestClassName extends NewParserTest {
00102     protected \$file = '$escapedFileName';
00103 }
00104 EOT;
00105 
00106             eval( $parserTestClassDefinition );
00107             self::debug( "Adding test class $parserTestClassName" );
00108             $suite->addTestSuite( $parserTestClassName );
00109         }
00110         return $suite;
00111     }
00112 
00117     protected static function debug( $msg ) {
00118         return wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg );
00119     }
00120 }