3 * Sanity checks for making sure registered resources are sane.
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
12 class ResourcesTest
extends MediaWikiTestCase
{
15 * @dataProvider provideResourceFiles
17 public function testFileExistence( $filename, $module, $resource ) {
18 $this->assertFileExists( $filename,
19 "File '$resource' referenced by '$module' must exist."
24 * This ask the ResouceLoader for all registered files from modules
25 * created by ResourceLoaderFileModule (or one of its descendants).
28 * Since the raw data is stored in protected properties, we have to
29 * overrride this through ReflectionObject methods.
31 public static function provideResourceFiles() {
32 global $wgEnableJavaScriptTest;
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;
39 // Array with arguments for the test function
42 // Initialize ResourceLoader
43 $rl = new ResourceLoader();
45 // See also ResourceLoaderFileModule::__construct
46 $filePathProps = array(
47 // Lists of file paths
55 // Collated lists of file paths
56 'nested-lists' => array(
63 foreach ( $rl->getModuleNames() as $moduleName ) {
64 $module = $rl->getModule( $moduleName );
65 if ( !$module instanceof ResourceLoaderFileModule
) {
69 $reflectedModule = new ReflectionObject( $module );
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 ) ) {
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 ) ) {
107 // Get method for resolving the paths to full paths
108 $method = $reflectedModule->getMethod( 'getLocalPath' );
109 $method->setAccessible( true );
112 foreach ( $files as $file ) {
114 $method->invoke( $module, $file ),
122 $wgEnableJavaScriptTest = $live_wgEnableJavaScriptTest;