MediaWiki  REL1_22
AutoLoaderTest.php
Go to the documentation of this file.
00001 <?php
00002 class AutoLoaderTest extends MediaWikiTestCase {
00003 
00010     public function testAutoLoadConfig() {
00011         $results = self::checkAutoLoadConf();
00012 
00013         $this->assertEquals(
00014             $results['expected'],
00015             $results['actual']
00016         );
00017     }
00018 
00019     protected static function checkAutoLoadConf() {
00020         global $wgAutoloadLocalClasses, $wgAutoloadClasses, $IP;
00021         $supportsParsekit = function_exists( 'parsekit_compile_file' );
00022 
00023         // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php
00024         $expected = $wgAutoloadLocalClasses + $wgAutoloadClasses;
00025         $actual = array();
00026 
00027         $files = array_unique( $expected );
00028 
00029         foreach ( $files as $file ) {
00030             // Only prefix $IP if it doesn't have it already.
00031             // Generally local classes don't have it, and those from extensions and test suites do.
00032             if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) {
00033                 $filePath = "$IP/$file";
00034             } else {
00035                 $filePath = $file;
00036             }
00037             if ( $supportsParsekit ) {
00038                 $parseInfo = parsekit_compile_file( "$filePath" );
00039                 $classes = array_keys( $parseInfo['class_table'] );
00040             } else {
00041                 $contents = file_get_contents( "$filePath" );
00042                 $m = array();
00043                 preg_match_all( '/\n\s*(?:final)?\s*(?:abstract)?\s*(?:class|interface)\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER );
00044                 $classes = $m[1];
00045             }
00046             foreach ( $classes as $class ) {
00047                 $actual[$class] = $file;
00048             }
00049         }
00050 
00051         return array(
00052             'expected' => $expected,
00053             'actual' => $actual,
00054         );
00055     }
00056 }