X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fresourceloader%2FResourceLoaderWikiModuleTest.php;h=4cf4071172d9836e804718c0419cc9dcd3b7e02b;hb=525bfbc8df855aa12e01868d92532cd64482dc7d;hp=4048ffe6d47c81321cd7ca5cfaef2b4a1ac8a135;hpb=9a6a3044ff568890543dad4eae4d6882ef4c6e37;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php index 4048ffe6d4..4cf4071172 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php @@ -1,6 +1,8 @@ assertEquals( $expected, $module->getTitleInfo( $context ), 'Title info' ); } + /** + * @covers ResourceLoaderWikiModule::preloadTitleInfo + */ + public function testGetPreloadedBadTitle() { + // Mock values + $pages = [ + // Covers else branch for invalid page name + '[x]' => [ 'type' => 'styles' ], + ]; + $titleInfo = []; + + // Set up objects + $module = $this->getMockBuilder( 'TestResourceLoaderWikiModule' ) + ->setMethods( [ 'getPages' ] ) ->getMock(); + $module->method( 'getPages' )->willReturn( $pages ); + $module::$returnFetchTitleInfo = $titleInfo; + $rl = new EmptyResourceLoader(); + $rl->register( 'testmodule', $module ); + $context = new ResourceLoaderContext( $rl, new FauxRequest() ); + + // Act + TestResourceLoaderWikiModule::preloadTitleInfo( + $context, + wfGetDB( DB_REPLICA ), + [ 'testmodule' ] + ); + + // Assert + $module = TestingAccessWrapper::newFromObject( $module ); + $this->assertEquals( $titleInfo, $module->getTitleInfo( $context ), 'Title info' ); + } + + /** + * @covers ResourceLoaderWikiModule::preloadTitleInfo + */ + public function testGetPreloadedTitleInfoEmpty() { + $context = new ResourceLoaderContext( new EmptyResourceLoader(), new FauxRequest() ); + // Covers early return + $this->assertSame( + null, + ResourceLoaderWikiModule::preloadTitleInfo( + $context, + wfGetDB( DB_REPLICA ), + [] + ) + ); + } + + public static function provideGetContent() { + return [ + 'Bad title' => [ null, '[x]' ], + 'Dead redirect' => [ null, [ + 'text' => 'Dead redirect', + 'title' => 'Dead_redirect', + 'redirect' => 1, + ] ], + 'Bad content model' => [ null, [ + 'text' => 'MediaWiki:Wikitext', + 'ns' => NS_MEDIAWIKI, + 'title' => 'Wikitext', + ] ], + 'No JS content found' => [ null, [ + 'text' => 'MediaWiki:Script.js', + 'ns' => NS_MEDIAWIKI, + 'title' => 'Script.js', + ] ], + 'No CSS content found' => [ null, [ + 'text' => 'MediaWiki:Styles.css', + 'ns' => NS_MEDIAWIKI, + 'title' => 'Script.css', + ] ], + ]; + } + + /** + * @covers ResourceLoaderWikiModule::getContent + * @dataProvider provideGetContent + */ + public function testGetContent( $expected, $title ) { + $context = $this->getResourceLoaderContext( [], new EmptyResourceLoader ); + $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' ) + ->setMethods( [ 'getContentObj' ] ) ->getMock(); + $module->expects( $this->any() ) + ->method( 'getContentObj' )->willReturn( null ); + + if ( is_array( $title ) ) { + $title += [ 'ns' => NS_MAIN, 'id' => 1, 'len' => 1, 'redirect' => 0 ]; + $titleText = $title['text']; + // Mock Title db access via LinkCache + MediaWikiServices::getInstance()->getLinkCache()->addGoodLinkObj( + $title['id'], + new TitleValue( $title['ns'], $title['title'] ), + $title['len'], + $title['redirect'] + ); + } else { + $titleText = $title; + } + + $module = TestingAccessWrapper::newFromObject( $module ); + $this->assertEquals( + $expected, + $module->getContent( $titleText ) + ); + + } + /** * @covers ResourceLoaderWikiModule::getContent */