MediaWiki  REL1_21
ResourcesTest.php
Go to the documentation of this file.
00001 <?php
00012 class ResourcesTest extends MediaWikiTestCase {
00013 
00017         public function testFileExistence( $filename, $module, $resource ) {
00018                 $this->assertFileExists( $filename,
00019                         "File '$resource' referenced by '$module' must exist."
00020                 );
00021         }
00022 
00031         public static function provideResourceFiles() {
00032                 global $wgEnableJavaScriptTest;
00033 
00034                 // Test existance of test suite files as well
00035                 // (can't use setUp or setMwGlobals because providers are static)
00036                 $live_wgEnableJavaScriptTest = $wgEnableJavaScriptTest;
00037                 $wgEnableJavaScriptTest = true;
00038 
00039                 // Array with arguments for the test function
00040                 $cases = array();
00041 
00042                 // Initialize ResourceLoader
00043                 $rl = new ResourceLoader();
00044 
00045                 // See also ResourceLoaderFileModule::__construct
00046                 $filePathProps = array(
00047                         // Lists of file paths
00048                         'lists' => array(
00049                                 'scripts',
00050                                 'debugScripts',
00051                                 'loaderScripts',
00052                                 'styles',
00053                         ),
00054 
00055                         // Collated lists of file paths
00056                         'nested-lists' => array(
00057                                 'languageScripts',
00058                                 'skinScripts',
00059                                 'skinStyles',
00060                         ),
00061                 );
00062 
00063                 foreach ( $rl->getModuleNames() as $moduleName ) {
00064                         $module = $rl->getModule( $moduleName );
00065                         if ( !$module instanceof ResourceLoaderFileModule ) {
00066                                 continue;
00067                         }
00068 
00069                         $reflectedModule = new ReflectionObject( $module );
00070 
00071                         $files = array();
00072 
00073                         foreach ( $filePathProps['lists'] as $propName ) {
00074                                 $property = $reflectedModule->getProperty( $propName );
00075                                 $property->setAccessible( true );
00076                                 $list = $property->getValue( $module );
00077                                 foreach ( $list as $key => $value ) {
00078                                         // 'scripts' are numeral arrays.
00079                                         // 'styles' can be numeral or associative.
00080                                         // In case of associative the key is the file path
00081                                         // and the value is the 'media' attribute.
00082                                         if ( is_int( $key ) ) {
00083                                                 $files[] = $value;
00084                                         } else {
00085                                                 $files[] = $key;
00086                                         }
00087                                 }
00088                         }
00089 
00090                         foreach ( $filePathProps['nested-lists'] as $propName ) {
00091                                 $property = $reflectedModule->getProperty( $propName );
00092                                 $property->setAccessible( true );
00093                                 $lists = $property->getValue( $module );
00094                                 foreach ( $lists as $group => $list ) {
00095                                         foreach ( $list as $key => $value ) {
00096                                                 // We need the same filter as for 'lists',
00097                                                 // due to 'skinStyles'.
00098                                                 if ( is_int( $key ) ) {
00099                                                         $files[] = $value;
00100                                                 } else {
00101                                                         $files[] = $key;
00102                                                 }
00103                                         }
00104                                 }
00105                         }
00106 
00107                         // Get method for resolving the paths to full paths
00108                         $method = $reflectedModule->getMethod( 'getLocalPath' );
00109                         $method->setAccessible( true );
00110 
00111                         // Populate cases
00112                         foreach ( $files as $file ) {
00113                                 $cases[] = array(
00114                                         $method->invoke( $module, $file ),
00115                                         $module->getName(),
00116                                         $file,
00117                                 );
00118                         }
00119 
00120                 }
00121 
00122                 // Restore settings
00123                 $wgEnableJavaScriptTest = $live_wgEnableJavaScriptTest;
00124 
00125                 return $cases;
00126         }
00127 
00128 }