Merge "Allow basic grant holders to autocreate accounts"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleTest.php
index 4ffef02..e8f0873 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use MediaWiki\Interwiki\InterwikiLookup;
 use MediaWiki\Linker\LinkTarget;
 use MediaWiki\MediaWikiServices;
 use Wikimedia\TestingAccessWrapper;
@@ -295,9 +296,15 @@ class TitleTest extends MediaWikiTestCase {
         * @covers Title::isValidMoveOperation
         */
        public function testIsValidMoveOperation( $source, $target, $expected ) {
+               global $wgMultiContentRevisionSchemaMigrationStage;
+
                $this->hideDeprecated( 'Title::isValidMoveOperation' );
 
-               $this->setMwGlobals( 'wgContentHandlerUseDB', false );
+               if ( $wgMultiContentRevisionSchemaMigrationStage === SCHEMA_COMPAT_OLD ) {
+                       // We can only set this to false with the old schema
+                       $this->setMwGlobals( 'wgContentHandlerUseDB', false );
+               }
+
                $title = Title::newFromText( $source );
                $nt = Title::newFromText( $target );
                $errors = $title->isValidMoveOperation( $nt, false );
@@ -312,16 +319,24 @@ class TitleTest extends MediaWikiTestCase {
        }
 
        public static function provideTestIsValidMoveOperation() {
-               return [
+               global $wgMultiContentRevisionSchemaMigrationStage;
+               $ret = [
                        // for Title::isValidMoveOperation
                        [ 'Some page', '', 'badtitletext' ],
                        [ 'Test', 'Test', 'selfmove' ],
                        [ 'Special:FooBar', 'Test', 'immobile-source-namespace' ],
                        [ 'Test', 'Special:FooBar', 'immobile-target-namespace' ],
-                       [ 'MediaWiki:Common.js', 'Help:Some wikitext page', 'bad-target-model' ],
                        [ 'Page', 'File:Test.jpg', 'nonfile-cannot-move-to-file' ],
                        [ 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ],
                ];
+               if ( $wgMultiContentRevisionSchemaMigrationStage === SCHEMA_COMPAT_OLD ) {
+                       // The error can only occur if $wgContentHandlerUseDB is false, which doesn't work with
+                       // the new schema, so omit the test in that case
+                       array_push( $ret,
+                               [ 'MediaWiki:Common.js', 'Help:Some wikitext page', 'bad-target-model' ]
+                       );
+               }
+               return $ret;
        }
 
        /**
@@ -553,6 +568,10 @@ class TitleTest extends MediaWikiTestCase {
                        # Title, expected base, optional message
                        [ 'User:John_Doe/subOne/subTwo', 'John Doe' ],
                        [ 'User:Foo / Bar / Baz', 'Foo ' ],
+                       [ 'Talk:////', '////' ],
+                       [ 'Template:////', '////' ],
+                       [ 'Template:Foo////', 'Foo' ],
+                       [ 'Template:Foo////Bar', 'Foo' ],
                ];
        }
 
@@ -577,6 +596,41 @@ class TitleTest extends MediaWikiTestCase {
                ];
        }
 
+       public function provideSubpage() {
+               // NOTE: avoid constructing Title objects in the provider, since it may access the database.
+               return [
+                       [ 'Foo', 'x', new TitleValue( NS_MAIN, 'Foo/x' ) ],
+                       [ 'Foo#bar', 'x', new TitleValue( NS_MAIN, 'Foo/x' ) ],
+                       [ 'User:Foo', 'x', new TitleValue( NS_USER, 'Foo/x' ) ],
+                       [ 'wiki:User:Foo', 'x', new TitleValue( NS_MAIN, 'User:Foo/x', '', 'wiki' ) ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideSubpage
+        * @covers Title::getSubpage
+        */
+       public function testSubpage( $title, $sub, LinkTarget $expected ) {
+               $interwikiLookup = $this->getMock( InterwikiLookup::class );
+               $interwikiLookup->expects( $this->any() )
+                       ->method( 'isValidInterwiki' )
+                       ->willReturnCallback(
+                               function ( $prefix ) {
+                                       return $prefix == 'wiki';
+                               }
+                       );
+
+               $this->setService( 'InterwikiLookup', $interwikiLookup );
+
+               $title = Title::newFromText( $title );
+               $expected = Title::newFromLinkTarget( $expected );
+               $actual = $title->getSubpage( $sub );
+
+               // NOTE: convert to string for comparison
+               $this->assertSame( $expected->getPrefixedText(), $actual->getPrefixedText(), 'text form' );
+               $this->assertTrue( $expected->equals( $actual ), 'Title equality' );
+       }
+
        public static function provideNewFromTitleValue() {
                return [
                        [ new TitleValue( NS_MAIN, 'Foo' ) ],
@@ -770,7 +824,7 @@ class TitleTest extends MediaWikiTestCase {
                // Tell Title it doesn't know whether it exists
                $title->mArticleID = -1;
 
-               // Tell the link cache it doesn't exists when it really does
+               // Tell the link cache it doesn't exist when it really does
                $linkCache->clearLink( $title );
                $linkCache->addBadLinkObj( $title );