Changed quoting function for oracleDB.
[mediawiki.git] / tests / phpunit / resources / ResourcesTest.php
blob3af805a958b9421db415d29290784ac215a87934
1 <?php
2 /**
3 * Sanity checks for making sure registered resources are sane.
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
12 class ResourcesTest extends MediaWikiTestCase {
14 /**
15 * @dataProvider provideResourceFiles
17 public function testFileExistence( $filename, $module, $resource ) {
18 $this->assertFileExists( $filename,
19 "File '$resource' referenced by '$module' must exist."
23 /**
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
40 $cases = array();
42 // Initialize ResourceLoader
43 $rl = new ResourceLoader();
45 // See also ResourceLoaderFileModule::__construct
46 $filePathProps = array(
47 // Lists of file paths
48 'lists' => array(
49 'scripts',
50 'debugScripts',
51 'loaderScripts',
52 'styles',
55 // Collated lists of file paths
56 'nested-lists' => array(
57 'languageScripts',
58 'skinScripts',
59 'skinStyles',
63 foreach ( $rl->getModuleNames() as $moduleName ) {
64 $module = $rl->getModule( $moduleName );
65 if ( !$module instanceof ResourceLoaderFileModule ) {
66 continue;
69 $reflectedModule = new ReflectionObject( $module );
71 $files = array();
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;
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;
107 // Get method for resolving the paths to full paths
108 $method = $reflectedModule->getMethod( 'getLocalPath' );
109 $method->setAccessible( true );
111 // Populate cases
112 foreach ( $files as $file ) {
113 $cases[] = array(
114 $method->invoke( $module, $file ),
115 $module->getName(),
116 $file,
121 // Restore settings
122 $wgEnableJavaScriptTest = $live_wgEnableJavaScriptTest;
124 return $cases;