<?php
+use Wikimedia\TestingAccessWrapper;
+
class ResourceLoaderTest extends ResourceLoaderTestCase {
protected function setUp() {
);
}
+ public function provideTestIsFileModule() {
+ $fileModuleObj = $this->getMockBuilder( ResourceLoaderFileModule::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ return [
+ 'object' => [ false,
+ new ResourceLoaderTestModule()
+ ],
+ 'FileModule object' => [ false,
+ $fileModuleObj
+ ],
+ 'simple empty' => [ true,
+ []
+ ],
+ 'simple scripts' => [ true,
+ [ 'scripts' => 'example.js' ]
+ ],
+ 'simple scripts, raw and targets' => [ true, [
+ 'scripts' => [ 'a.js', 'b.js' ],
+ 'raw' => true,
+ 'targets' => [ 'desktop', 'mobile' ],
+ ] ],
+ 'FileModule' => [ true,
+ [ 'class' => ResourceLoaderFileModule::class, 'scripts' => 'example.js' ]
+ ],
+ 'TestModule' => [ false,
+ [ 'class' => ResourceLoaderTestModule::class, 'scripts' => 'example.js' ]
+ ],
+ 'SkinModule (FileModule subclass)' => [ true,
+ [ 'class' => ResourceLoaderSkinModule::class, 'scripts' => 'example.js' ]
+ ],
+ 'JqueryMsgModule (FileModule subclass)' => [ true, [
+ 'class' => ResourceLoaderJqueryMsgModule::class,
+ 'scripts' => 'example.js',
+ ] ],
+ 'WikiModule' => [ false, [
+ 'class' => ResourceLoaderWikiModule::class,
+ 'scripts' => [ 'MediaWiki:Example.js' ],
+ ] ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideTestIsFileModule
+ * @covers ResourceLoader::isFileModule
+ */
+ public function testIsFileModule( $expected, $module ) {
+ $rl = TestingAccessWrapper::newFromObject( new EmptyResourceLoader() );
+ $rl->register( 'test', $module );
+ $this->assertSame( $expected, $rl->isFileModule( 'test' ) );
+ }
+
/**
* @covers ResourceLoader::isModuleRegistered
*/
);
}
+ /**
+ * @covers ResourceLoader::getModule
+ */
+ public function testGetModuleFactory() {
+ $factory = function ( array $info ) {
+ $this->assertArrayHasKey( 'kitten', $info );
+ return new ResourceLoaderTestModule( $info );
+ };
+
+ $rl = new EmptyResourceLoader();
+ $rl->register( 'test', [ 'factory' => $factory, 'kitten' => 'little ball of fur' ] );
+ $this->assertInstanceOf(
+ ResourceLoaderTestModule::class,
+ $rl->getModule( 'test' )
+ );
+ }
+
/**
* @covers ResourceLoader::getModule
*/
* Verify that when building module content in a load.php response,
* an exception from one module will not break script output from
* other modules.
+ *
+ * @covers ResourceLoader::makeModuleResponse
*/
public function testMakeModuleResponseError() {
$modules = [
* Verify that when building the startup module response,
* an exception from one module class will not break the entire
* startup module response. See T152266.
+ *
+ * @covers ResourceLoader::makeModuleResponse
*/
public function testMakeModuleResponseStartupError() {
$rl = new EmptyResourceLoader();