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