Merge "MWUI: Vertically align the icon pseudo elements"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleTest.php
index b3465e1..7850f24 100644 (file)
@@ -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() );
+       }
 }