Remove hard deprecation of PasswordPolicyChecks::checkPopularPasswordBlacklist
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleMethodsTest.php
index 44d440f..77d6f59 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use MediaWiki\Interwiki\InterwikiLookup;
 use MediaWiki\MediaWikiServices;
 
 /**
@@ -30,30 +31,6 @@ class TitleMethodsTest extends MediaWikiLangTestCase {
                );
        }
 
-       public static function provideEquals() {
-               return [
-                       [ 'Main Page', 'Main Page', true ],
-                       [ 'Main Page', 'Not The Main Page', false ],
-                       [ 'Main Page', 'Project:Main Page', false ],
-                       [ 'File:Example.png', 'Image:Example.png', true ],
-                       [ 'Special:Version', 'Special:Version', true ],
-                       [ 'Special:Version', 'Special:Recentchanges', false ],
-                       [ 'Special:Version', 'Main Page', false ],
-               ];
-       }
-
-       /**
-        * @dataProvider provideEquals
-        * @covers Title::equals
-        */
-       public function testEquals( $titleA, $titleB, $expectedBool ) {
-               $titleA = Title::newFromText( $titleA );
-               $titleB = Title::newFromText( $titleB );
-
-               $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
-               $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
-       }
-
        public static function provideInNamespace() {
                return [
                        [ 'Main Page', NS_MAIN, true ],
@@ -353,6 +330,138 @@ class TitleMethodsTest extends MediaWikiLangTestCase {
                $this->assertEquals( 0, $linkCache->getGoodLinkID( 'Foo' ), 'link cache should be empty' );
        }
 
+       public function provideGetLinkURL() {
+               yield 'Simple' => [
+                       '/wiki/Goats',
+                       NS_MAIN,
+                       'Goats'
+               ];
+
+               yield 'Fragment' => [
+                       '/wiki/Goats#Goatificatiön',
+                       NS_MAIN,
+                       'Goats',
+                       'Goatificatiön'
+               ];
+
+               yield 'Unknown interwiki with fragment' => [
+                       'https://xx.wiki.test/wiki/xyzzy:Goats#Goatificatiön',
+                       NS_MAIN,
+                       'Goats',
+                       'Goatificatiön',
+                       'xyzzy'
+               ];
+
+               yield 'Interwiki with fragment' => [
+                       'https://acme.test/Goats#Goatificati.C3.B6n',
+                       NS_MAIN,
+                       'Goats',
+                       'Goatificatiön',
+                       'acme'
+               ];
+
+               yield 'Interwiki with query' => [
+                       'https://acme.test/Goats?a=1&b=blank+blank#Goatificati.C3.B6n',
+                       NS_MAIN,
+                       'Goats',
+                       'Goatificatiön',
+                       'acme',
+                       [
+                               'a' => 1,
+                               'b' => 'blank blank'
+                       ]
+               ];
+
+               yield 'Local interwiki with fragment' => [
+                       'https://yy.wiki.test/wiki/Goats#Goatificatiön',
+                       NS_MAIN,
+                       'Goats',
+                       'Goatificatiön',
+                       'yy'
+               ];
+       }
+
+       /**
+        * @dataProvider provideGetLinkURL
+        *
+        * @covers Title::getLinkURL
+        * @covers Title::getFullURL
+        * @covers Title::getLocalURL
+        * @covers Title::getFragmentForURL
+        */
+       public function testGetLinkURL(
+               $expected,
+               $ns,
+               $title,
+               $fragment = '',
+               $interwiki = '',
+               $query = '',
+               $query2 = false,
+               $proto = false
+       ) {
+               $this->setMwGlobals( [
+                       'wgServer' => 'https://xx.wiki.test',
+                       'wgArticlePath' => '/wiki/$1',
+                       'wgExternalInterwikiFragmentMode' => 'legacy',
+                       'wgFragmentMode' => [ 'html5', 'legacy' ]
+               ] );
+
+               $interwikiLookup = $this->getMock( InterwikiLookup::class );
+
+               $interwikiLookup->method( 'fetch' )
+                       ->willReturnCallback( function ( $interwiki ) {
+                               switch ( $interwiki ) {
+                                       case '':
+                                               return null;
+                                       case 'acme':
+                                               return new Interwiki(
+                                                       'acme',
+                                                       'https://acme.test/$1'
+                                               );
+                                       case 'yy':
+                                               return new Interwiki(
+                                                       'yy',
+                                                       'https://yy.wiki.test/wiki/$1',
+                                                       '/w/api.php',
+                                                       'yywiki',
+                                                       true
+                                               );
+                                       default:
+                                               return false;
+                               }
+                       } );
+
+               $this->setService( 'InterwikiLookup', $interwikiLookup );
+
+               $title = Title::makeTitle( $ns, $title, $fragment, $interwiki );
+               $this->assertSame( $expected, $title->getLinkURL( $query, $query2, $proto ) );
+       }
+
+       /**
+        * Integration test to catch regressions like T74870. Taken and modified
+        * from SemanticMediaWiki
+        *
+        * @covers Title::moveTo
+        */
+       public function testTitleMoveCompleteIntegrationTest() {
+               $this->hideDeprecated( 'Title::moveTo' );
+
+               $oldTitle = Title::newFromText( 'Help:Some title' );
+               WikiPage::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
+               $newTitle = Title::newFromText( 'Help:Some other title' );
+               $this->assertNull(
+                       WikiPage::factory( $newTitle )->getRevision()
+               );
+
+               $this->assertTrue( $oldTitle->moveTo( $newTitle, false, 'test1', true ) );
+               $this->assertNotNull(
+                       WikiPage::factory( $oldTitle )->getRevision()
+               );
+               $this->assertNotNull(
+                       WikiPage::factory( $newTitle )->getRevision()
+               );
+       }
+
        function tearDown() {
                Title::clearCaches();
                parent::tearDown();