3 * Sanity checks for making sure registered resources are sane.
6 * @author Antoine Musso
7 * @author Niklas Laxström
8 * @author Santhosh Thottingal
10 * @copyright © 2012, Antoine Musso
11 * @copyright © 2012, Niklas Laxström
12 * @copyright © 2012, Santhosh Thottingal
13 * @copyright © 2012, Timo Tijhof
15 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
17 class ResourcesTest
extends MediaWikiTestCase
{
20 * @dataProvider provideResourceFiles
22 public function testFileExistence( $filename, $module, $resource ) {
23 $this->assertFileExists( $filename,
24 "File '$resource' referenced by '$module' must exist."
29 * This ask the ResouceLoader for all registered files from modules
30 * created by ResourceLoaderFileModule (or one of its descendants).
33 * Since the raw data is stored in protected properties, we have to
34 * overrride this through ReflectionObject methods.
36 public static function provideResourceFiles() {
37 global $wgEnableJavaScriptTest;
39 // Test existance of test suite files as well
40 // (can't use setUp or setMwGlobals because providers are static)
41 $live_wgEnableJavaScriptTest = $wgEnableJavaScriptTest;
42 $wgEnableJavaScriptTest = true;
44 // Array with arguments for the test function
47 // Initialize ResourceLoader
48 $rl = new ResourceLoader();
50 // See also ResourceLoaderFileModule::__construct
51 $filePathProps = array(
52 // Lists of file paths
60 // Collated lists of file paths
61 'nested-lists' => array(
68 foreach ( $rl->getModuleNames() as $moduleName ) {
69 $module = $rl->getModule( $moduleName );
70 if ( !$module instanceof ResourceLoaderFileModule
) {
74 $reflectedModule = new ReflectionObject( $module );
78 foreach ( $filePathProps['lists'] as $propName ) {
79 $property = $reflectedModule->getProperty( $propName );
80 $property->setAccessible( true );
81 $list = $property->getValue( $module );
82 foreach ( $list as $key => $value ) {
83 // 'scripts' are numeral arrays.
84 // 'styles' can be numeral or associative.
85 // In case of associative the key is the file path
86 // and the value is the 'media' attribute.
87 if ( is_int( $key ) ) {
95 foreach ( $filePathProps['nested-lists'] as $propName ) {
96 $property = $reflectedModule->getProperty( $propName );
97 $property->setAccessible( true );
98 $lists = $property->getValue( $module );
99 foreach ( $lists as $list ) {
100 foreach ( $list as $key => $value ) {
101 // We need the same filter as for 'lists',
102 // due to 'skinStyles'.
103 if ( is_int( $key ) ) {
112 // Get method for resolving the paths to full paths
113 $method = $reflectedModule->getMethod( 'getLocalPath' );
114 $method->setAccessible( true );
117 foreach ( $files as $file ) {
119 $method->invoke( $module, $file ),
127 $wgEnableJavaScriptTest = $live_wgEnableJavaScriptTest;