X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTitleTest.php;h=7850f2490cb86cd4b93aef61e7f01acc713b1e59;hb=0acba338989197c6c187452dacf5efaa7a5838aa;hp=f2ad1c6172a063ef6449ad8948063b08f63d6539;hpb=9ba3fca2d8adc56787c8efc32c41424cb212e387;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index f2ad1c6172..7850f2490c 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -9,14 +9,12 @@ class TitleTest extends MediaWikiTestCase { parent::setUp(); $this->setMwGlobals( [ - 'wgLanguageCode' => 'en', - 'wgContLang' => Language::factory( 'en' ), - // User language - 'wgLang' => Language::factory( 'en' ), 'wgAllowUserJs' => false, 'wgDefaultLanguageVariant' => false, 'wgMetaNamespace' => 'Project', ] ); + $this->setUserLang( 'en' ); + $this->setContentLang( 'en' ); } /** @@ -146,6 +144,13 @@ class TitleTest extends MediaWikiTestCase { ] ] ] ); + + // Reset TitleParser since we modified $wgLocalInterwikis + $this->setService( 'TitleParser', new MediaWikiTitleCodec( + Language::factory( 'en' ), + new GenderCache(), + [ 'localtestiw' ] + ) ); } /** @@ -421,12 +426,11 @@ class TitleTest extends MediaWikiTestCase { ) { // Setup environnement for this test $this->setMwGlobals( [ - 'wgLanguageCode' => $contLang, - 'wgContLang' => Language::factory( $contLang ), - 'wgLang' => Language::factory( $lang ), 'wgDefaultLanguageVariant' => $variant, 'wgAllowUserJs' => true, ] ); + $this->setUserLang( $lang ); + $this->setContentLang( $contLang ); $title = Title::newFromText( $titleText ); $this->assertInstanceOf( 'Title', $title, @@ -668,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() ); + } }