X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fresourceloader%2FResourceLoaderWikiModuleTest.php;h=5cab8e2ff6d3e05f1c8e8978d9aef58fcce61bba;hp=a332528ffb9ad72cdb00ae3fdbffd59225f2cb7c;hb=488a647831011f8d1e8f8969ee7ae04d2498366f;hpb=69ae945e8d39972a07bea89ddb64bc0189b43ac2 diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php index a332528ffb..5cab8e2ff6 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php @@ -1,5 +1,8 @@ assertEquals( $expected, $module->getTitleInfo( $context ), 'Title info' ); } + + /** + * @covers ResourceLoaderWikiModule::getContent + */ + public function testGetContentForRedirects() { + // Set up context and module object + $context = $this->getResourceLoaderContext( [], new EmptyResourceLoader ); + $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' ) + ->setMethods( [ 'getPages', 'getContentObj' ] ) + ->getMock(); + $module->expects( $this->any() ) + ->method( 'getPages' ) + ->will( $this->returnValue( [ + 'MediaWiki:Redirect.js' => [ 'type' => 'script' ] + ] ) ); + $module->expects( $this->any() ) + ->method( 'getContentObj' ) + ->will( $this->returnCallback( function ( Title $title ) { + if ( $title->getPrefixedText() === 'MediaWiki:Redirect.js' ) { + $handler = new JavaScriptContentHandler(); + return $handler->makeRedirectContent( + Title::makeTitle( NS_MEDIAWIKI, 'Target.js' ) + ); + } elseif ( $title->getPrefixedText() === 'MediaWiki:Target.js' ) { + return new JavaScriptContent( 'target;' ); + } else { + return null; + } + } ) ); + + // Mock away Title's db queries with LinkCache + MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObj( + 1, // id + new TitleValue( NS_MEDIAWIKI, 'Redirect.js' ), + 1, // len + 1 // redirect + ); + + $this->assertEquals( + "/*\nMediaWiki:Redirect.js\n*/\ntarget;\n", + $module->getScript( $context ), + 'Redirect resolved by getContent' + ); + } } class TestResourceLoaderWikiModule extends ResourceLoaderWikiModule {