Merge "Add fa to collation list."
[lhc/web/wiklou.git] / tests / phpunit / structure / ResourcesTest.php
1 <?php
2 /**
3 * Sanity checks for making sure registered resources are sane.
4 *
5 * @file
6 * @author Niklas Laxström, 2012
7 * @author Antoine Musso, 2012
8 * @author Santhosh Thottingal, 2012
9 * @author Timo Tijhof, 2012
10 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
11 */
12 class ResourcesTest extends MediaWikiTestCase {
13
14 /**
15 * @dataProvider provideResourceFiles
16 */
17 public function testFileExistence( $filename, $module, $resource ) {
18 $this->assertFileExists( $filename,
19 "File '$resource' referenced by '$module' must exist."
20 );
21 }
22
23 /**
24 * This ask the ResouceLoader for all registered files from modules
25 * created by ResourceLoaderFileModule (or one of its descendants).
26 *
27 *
28 * Since the raw data is stored in protected properties, we have to
29 * overrride this through ReflectionObject methods.
30 */
31 public static function provideResourceFiles() {
32 global $wgEnableJavaScriptTest;
33
34 // Test existance of test suite files as well
35 // (can't use setUp or setMwGlobals because providers are static)
36 $live_wgEnableJavaScriptTest = $wgEnableJavaScriptTest;
37 $wgEnableJavaScriptTest = true;
38
39 // Array with arguments for the test function
40 $cases = array();
41
42 // Initialize ResourceLoader
43 $rl = new ResourceLoader();
44
45 // See also ResourceLoaderFileModule::__construct
46 $filePathProps = array(
47 // Lists of file paths
48 'lists' => array(
49 'scripts',
50 'debugScripts',
51 'loaderScripts',
52 'styles',
53 ),
54
55 // Collated lists of file paths
56 'nested-lists' => array(
57 'languageScripts',
58 'skinScripts',
59 'skinStyles',
60 ),
61 );
62
63 foreach ( $rl->getModuleNames() as $moduleName ) {
64 $module = $rl->getModule( $moduleName );
65 if ( !$module instanceof ResourceLoaderFileModule ) {
66 continue;
67 }
68
69 $reflectedModule = new ReflectionObject( $module );
70
71 $files = array();
72
73 foreach ( $filePathProps['lists'] as $propName ) {
74 $property = $reflectedModule->getProperty( $propName );
75 $property->setAccessible( true );
76 $list = $property->getValue( $module );
77 foreach ( $list as $key => $value ) {
78 // 'scripts' are numeral arrays.
79 // 'styles' can be numeral or associative.
80 // In case of associative the key is the file path
81 // and the value is the 'media' attribute.
82 if ( is_int( $key ) ) {
83 $files[] = $value;
84 } else {
85 $files[] = $key;
86 }
87 }
88 }
89
90 foreach ( $filePathProps['nested-lists'] as $propName ) {
91 $property = $reflectedModule->getProperty( $propName );
92 $property->setAccessible( true );
93 $lists = $property->getValue( $module );
94 foreach ( $lists as $list ) {
95 foreach ( $list as $key => $value ) {
96 // We need the same filter as for 'lists',
97 // due to 'skinStyles'.
98 if ( is_int( $key ) ) {
99 $files[] = $value;
100 } else {
101 $files[] = $key;
102 }
103 }
104 }
105 }
106
107 // Get method for resolving the paths to full paths
108 $method = $reflectedModule->getMethod( 'getLocalPath' );
109 $method->setAccessible( true );
110
111 // Populate cases
112 foreach ( $files as $file ) {
113 $cases[] = array(
114 $method->invoke( $module, $file ),
115 $module->getName(),
116 $file,
117 );
118 }
119 }
120
121 // Restore settings
122 $wgEnableJavaScriptTest = $live_wgEnableJavaScriptTest;
123
124 return $cases;
125 }
126 }