MediaWiki  REL1_23
ResourceLoaderStartupModuleTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class ResourceLoaderStartupModuleTest extends ResourceLoaderTestCase {
00004 
00005     public static function provideGetModuleRegistrations() {
00006         return array(
00007             array( array(
00008                 'msg' => 'Empty registry',
00009                 'modules' => array(),
00010                 'out' => '
00011 mw.loader.addSource( {
00012     "local": {
00013         "loadScript": "/w/load.php",
00014         "apiScript": "/w/api.php"
00015     }
00016 } );mw.loader.register( [] );'
00017             ) ),
00018             array( array(
00019                 'msg' => 'Basic registry',
00020                 'modules' => array(
00021                     'test.blank' => new ResourceLoaderTestModule(),
00022                 ),
00023                 'out' => '
00024 mw.loader.addSource( {
00025     "local": {
00026         "loadScript": "/w/load.php",
00027         "apiScript": "/w/api.php"
00028     }
00029 } );mw.loader.register( [
00030     [
00031         "test.blank",
00032         "1388534400"
00033     ]
00034 ] );',
00035             ) ),
00036             array( array(
00037                 'msg' => 'Group signature',
00038                 'modules' => array(
00039                     'test.blank' => new ResourceLoaderTestModule(),
00040                     'test.group.foo' => new ResourceLoaderTestModule( array( 'group' => 'x-foo' ) ),
00041                     'test.group.bar' => new ResourceLoaderTestModule( array( 'group' => 'x-bar' ) ),
00042                 ),
00043                 'out' => '
00044 mw.loader.addSource( {
00045     "local": {
00046         "loadScript": "/w/load.php",
00047         "apiScript": "/w/api.php"
00048     }
00049 } );mw.loader.register( [
00050     [
00051         "test.blank",
00052         "1388534400"
00053     ],
00054     [
00055         "test.group.foo",
00056         "1388534400",
00057         [],
00058         "x-foo"
00059     ],
00060     [
00061         "test.group.bar",
00062         "1388534400",
00063         [],
00064         "x-bar"
00065     ]
00066 ] );'
00067             ) ),
00068             array( array(
00069                 'msg' => 'Different target (non-test should not be registered)',
00070                 'modules' => array(
00071                     'test.blank' => new ResourceLoaderTestModule(),
00072                     'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
00073                 ),
00074                 'out' => '
00075 mw.loader.addSource( {
00076     "local": {
00077         "loadScript": "/w/load.php",
00078         "apiScript": "/w/api.php"
00079     }
00080 } );mw.loader.register( [
00081     [
00082         "test.blank",
00083         "1388534400"
00084     ]
00085 ] );'
00086             ) ),
00087             array( array(
00088                 'msg' => 'Foreign source',
00089                 'sources' => array(
00090                     'example' => array(
00091                         'loadScript' => 'http://example.org/w/load.php',
00092                         'apiScript' => 'http://example.org/w/api.php',
00093                     ),
00094                 ),
00095                 'modules' => array(
00096                     'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
00097                 ),
00098                 'out' => '
00099 mw.loader.addSource( {
00100     "local": {
00101         "loadScript": "/w/load.php",
00102         "apiScript": "/w/api.php"
00103     },
00104     "example": {
00105         "loadScript": "http://example.org/w/load.php",
00106         "apiScript": "http://example.org/w/api.php"
00107     }
00108 } );mw.loader.register( [
00109     [
00110         "test.blank",
00111         "1388534400",
00112         [],
00113         null,
00114         "example"
00115     ]
00116 ] );'
00117             ) ),
00118             array( array(
00119                 // This may seem like an edge case, but a plain MediaWiki core install
00120                 // with a few extensions installed is likely far more complex than this
00121                 // even, not to mention an install like Wikipedia.
00122                 // TODO: Make this even more realistic.
00123                 'msg' => 'Advanced (everything combined)',
00124                 'sources' => array(
00125                     'example' => array(
00126                         'loadScript' => 'http://example.org/w/load.php',
00127                         'apiScript' => 'http://example.org/w/api.php',
00128                     ),
00129                 ),
00130                 'modules' => array(
00131                     'test.blank' => new ResourceLoaderTestModule(),
00132                     'test.x.core' => new ResourceLoaderTestModule(),
00133                     'test.x.util' => new ResourceLoaderTestModule( array(
00134                         'dependencies' => array(
00135                             'test.x.core',
00136                         ),
00137                     ) ),
00138                     'test.x.foo' => new ResourceLoaderTestModule( array(
00139                         'dependencies' => array(
00140                             'test.x.core',
00141                         ),
00142                     ) ),
00143                     'test.x.bar' => new ResourceLoaderTestModule( array(
00144                         'dependencies' => array(
00145                             'test.x.core',
00146                             'test.x.util',
00147                         ),
00148                     ) ),
00149                     'test.x.quux' => new ResourceLoaderTestModule( array(
00150                         'dependencies' => array(
00151                             'test.x.foo',
00152                             'test.x.bar',
00153                             'test.x.util',
00154                         ),
00155                     ) ),
00156                     'test.group.foo.1' => new ResourceLoaderTestModule( array(
00157                         'group' => 'x-foo',
00158                     ) ),
00159                     'test.group.foo.2' => new ResourceLoaderTestModule( array(
00160                         'group' => 'x-foo',
00161                     ) ),
00162                     'test.group.bar.1' => new ResourceLoaderTestModule( array(
00163                         'group' => 'x-bar',
00164                     ) ),
00165                     'test.group.bar.2' => new ResourceLoaderTestModule( array(
00166                         'group' => 'x-bar',
00167                         'source' => 'example',
00168                     ) ),
00169                     'test.target.foo' => new ResourceLoaderTestModule( array(
00170                         'targets' => array( 'x-foo' ),
00171                     ) ),
00172                     'test.target.bar' => new ResourceLoaderTestModule( array(
00173                         'source' => 'example',
00174                         'targets' => array( 'x-foo' ),
00175                     ) ),
00176                 ),
00177                 'out' => '
00178 mw.loader.addSource( {
00179     "local": {
00180         "loadScript": "/w/load.php",
00181         "apiScript": "/w/api.php"
00182     },
00183     "example": {
00184         "loadScript": "http://example.org/w/load.php",
00185         "apiScript": "http://example.org/w/api.php"
00186     }
00187 } );mw.loader.register( [
00188     [
00189         "test.blank",
00190         "1388534400"
00191     ],
00192     [
00193         "test.x.core",
00194         "1388534400"
00195     ],
00196     [
00197         "test.x.util",
00198         "1388534400",
00199         [
00200             "test.x.core"
00201         ]
00202     ],
00203     [
00204         "test.x.foo",
00205         "1388534400",
00206         [
00207             "test.x.core"
00208         ]
00209     ],
00210     [
00211         "test.x.bar",
00212         "1388534400",
00213         [
00214             "test.x.core",
00215             "test.x.util"
00216         ]
00217     ],
00218     [
00219         "test.x.quux",
00220         "1388534400",
00221         [
00222             "test.x.foo",
00223             "test.x.bar",
00224             "test.x.util"
00225         ]
00226     ],
00227     [
00228         "test.group.foo.1",
00229         "1388534400",
00230         [],
00231         "x-foo"
00232     ],
00233     [
00234         "test.group.foo.2",
00235         "1388534400",
00236         [],
00237         "x-foo"
00238     ],
00239     [
00240         "test.group.bar.1",
00241         "1388534400",
00242         [],
00243         "x-bar"
00244     ],
00245     [
00246         "test.group.bar.2",
00247         "1388534400",
00248         [],
00249         "x-bar",
00250         "example"
00251     ]
00252 ] );'
00253             ) ),
00254         );
00255     }
00256 
00261     public function testGetModuleRegistrations( $case ) {
00262         if ( isset( $case['sources'] ) ) {
00263             $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
00264         }
00265 
00266         $context = self::getResourceLoaderContext();
00267         $rl = $context->getResourceLoader();
00268 
00269         $rl->register( $case['modules'] );
00270 
00271         $this->assertEquals(
00272             ltrim( $case['out'], "\n" ),
00273             ResourceLoaderStartUpModule::getModuleRegistrations( $context ),
00274             $case['msg']
00275         );
00276     }
00277 
00278 }