X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTitleTest.php;h=7850f2490cb86cd4b93aef61e7f01acc713b1e59;hb=0acba338989197c6c187452dacf5efaa7a5838aa;hp=b3465e1a855f3a5621ba23296ad8a998a4d0ca21;hpb=5c6a0cf57d98ed517b9470ba21e5b9e6141e0ea8;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index b3465e1a85..7850f2490c 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -144,6 +144,13 @@ class TitleTest extends MediaWikiTestCase { ] ] ] ); + + // Reset TitleParser since we modified $wgLocalInterwikis + $this->setService( 'TitleParser', new MediaWikiTitleCodec( + Language::factory( 'en' ), + new GenderCache(), + [ 'localtestiw' ] + ) ); } /** @@ -665,4 +672,79 @@ class TitleTest extends MediaWikiTestCase { 'exists() should re-query database when GAID_FOR_UPDATE is used' ); } + + public function provideCreateFragmentTitle() { + return [ + [ Title::makeTitle( NS_MAIN, 'Test' ), 'foo' ], + [ Title::makeTitle( NS_TALK, 'Test', 'foo' ), '' ], + [ Title::makeTitle( NS_CATEGORY, 'Test', 'foo' ), 'bar' ], + [ Title::makeTitle( NS_MAIN, 'Test1', '', 'interwiki' ), 'baz' ] + ]; + } + + /** + * @covers Title::createFragmentTarget + * @dataProvider provideCreateFragmentTitle + */ + public function testCreateFragmentTitle( Title $title, $fragment ) { + $this->mergeMwGlobalArrayValue( 'wgHooks', [ + 'InterwikiLoadPrefix' => [ + function ( $prefix, &$iwdata ) { + if ( $prefix === 'interwiki' ) { + $iwdata = [ + 'iw_url' => 'http://example.com/', + 'iw_local' => 0, + 'iw_trans' => 0, + ]; + return false; + } + }, + ], + ] ); + + $fragmentTitle = $title->createFragmentTarget( $fragment ); + + $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() ); + $this->assertEquals( $title->getText(), $fragmentTitle->getText() ); + $this->assertEquals( $title->getInterwiki(), $fragmentTitle->getInterwiki() ); + $this->assertEquals( $fragment, $fragmentTitle->getFragment() ); + } + + public function provideGetPrefixedText() { + return [ + // ns = 0 + [ + Title::makeTitle( NS_MAIN, 'Foobar' ), + 'Foobar' + ], + // ns = 2 + [ + Title::makeTitle( NS_USER, 'Foobar' ), + 'User:Foobar' + ], + // fragment not included + [ + Title::makeTitle( NS_MAIN, 'Foobar', 'fragment' ), + 'Foobar' + ], + // ns = -2 + [ + Title::makeTitle( NS_MEDIA, 'Foobar' ), + 'Media:Foobar' + ], + // non-existent namespace + [ + Title::makeTitle( 100000, 'Foobar' ), + ':Foobar' + ], + ]; + } + + /** + * @covers Title::getPrefixedText + * @dataProvider provideGetPrefixedText + */ + public function testGetPrefixedText( Title $title, $expected ) { + $this->assertEquals( $expected, $title->getPrefixedText() ); + } }