/** * @covers ResourceLoader::getModule */ public function testGetModuleClassDefault() { $rl = new EmptyResourceLoader(); $rl->register('test', []); $this->assertInstanceOf(ResourceLoaderFileModule::class, $rl->getModule('test'), 'Array-style module registrations default to FileModule'); }
/** * @covers ResourceLoaderContext::getImageObj */ public function testContext() { $context = new ResourceLoaderContext(new EmptyResourceLoader(), new FauxRequest()); $this->assertFalse($context->getImageObj(), 'Missing image parameter'); $context = new ResourceLoaderContext(new EmptyResourceLoader(), new FauxRequest(['image' => 'example'])); $this->assertFalse($context->getImageObj(), 'Missing module parameter'); $context = new ResourceLoaderContext(new EmptyResourceLoader(), new FauxRequest(['modules' => 'unknown', 'image' => 'example'])); $this->assertFalse($context->getImageObj(), 'Not an image module'); $rl = new EmptyResourceLoader(); $rl->register('test', ['class' => ResourceLoaderImageModule::class, 'prefix' => 'test', 'images' => ['example' => 'example.png']]); $context = new ResourceLoaderContext($rl, new FauxRequest(['modules' => 'test', 'image' => 'unknown'])); $this->assertFalse($context->getImageObj(), 'Unknown image'); $rl = new EmptyResourceLoader(); $rl->register('test', ['class' => ResourceLoaderImageModule::class, 'prefix' => 'test', 'images' => ['example' => 'example.png']]); $context = new ResourceLoaderContext($rl, new FauxRequest(['modules' => 'test', 'image' => 'example'])); $this->assertInstanceOf(ResourceLoaderImage::class, $context->getImageObj()); }
/** * @covers ResourceLoaderWikiModule::getTitleInfo * @covers ResourceLoaderWikiModule::setTitleInfo * @covers ResourceLoaderWikiModule::preloadTitleInfo */ public function testGetPreloadedTitleInfo() { $pages = ['MediaWiki:Common.css' => ['type' => 'styles'], 'mediawiki: fallback.css' => ['type' => 'styles']]; $titleInfo = ['MediaWiki:Common.css' => ['page_len' => 1234], 'MediaWiki:Fallback.css' => ['page_len' => 0]]; $expected = $titleInfo; $module = $this->getMockBuilder('TestResourceLoaderWikiModule')->setMethods(['getPages'])->getMock(); $module->method('getPages')->willReturn($pages); // Can't mock static methods $module::$returnFetchTitleInfo = $titleInfo; $rl = new EmptyResourceLoader(); $rl->register('testmodule', $module); $context = new ResourceLoaderContext($rl, new FauxRequest()); TestResourceLoaderWikiModule::invalidateModuleCache(Title::newFromText('MediaWiki:Common.css'), null, null, wfWikiID()); TestResourceLoaderWikiModule::preloadTitleInfo($context, wfGetDB(DB_REPLICA), ['testmodule']); $module = TestingAccessWrapper::newFromObject($module); $this->assertEquals($expected, $module->getTitleInfo($context), 'Title info'); }