Merge "Split some Language methods to LanguageNameUtils"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleTest.php
index 913f56d..6cfc377 100644 (file)
@@ -3,7 +3,6 @@
 use MediaWiki\Interwiki\InterwikiLookup;
 use MediaWiki\Linker\LinkTarget;
 use MediaWiki\MediaWikiServices;
-use Wikimedia\TestingAccessWrapper;
 
 /**
  * @group Database
@@ -22,12 +21,6 @@ class TitleTest extends MediaWikiTestCase {
                $this->setContentLang( 'en' );
        }
 
-       protected function tearDown() {
-               // For testNewMainPage
-               MessageCache::destroyInstance();
-               parent::tearDown();
-       }
-
        /**
         * @covers Title::legalChars
         */
@@ -286,45 +279,6 @@ class TitleTest extends MediaWikiTestCase {
                ];
        }
 
-       /**
-        * Auth-less test of Title::isValidMoveOperation
-        *
-        * @param string $source
-        * @param string $target
-        * @param array|string|bool $expected Required error
-        * @dataProvider provideTestIsValidMoveOperation
-        * @covers Title::isValidMoveOperation
-        */
-       public function testIsValidMoveOperation( $source, $target, $expected ) {
-               $this->hideDeprecated( 'Title::isValidMoveOperation' );
-
-               $this->setMwGlobals( 'wgContentHandlerUseDB', false );
-               $title = Title::newFromText( $source );
-               $nt = Title::newFromText( $target );
-               $errors = $title->isValidMoveOperation( $nt, false );
-               if ( $expected === true ) {
-                       $this->assertTrue( $errors );
-               } else {
-                       $errors = $this->flattenErrorsArray( $errors );
-                       foreach ( (array)$expected as $error ) {
-                               $this->assertContains( $error, $errors );
-                       }
-               }
-       }
-
-       public static function provideTestIsValidMoveOperation() {
-               return [
-                       // 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' ],
-               ];
-       }
-
        /**
         * Auth-less test of Title::userCan
         *
@@ -810,7 +764,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 );
 
@@ -993,6 +947,41 @@ class TitleTest extends MediaWikiTestCase {
                $title->getOtherPage();
        }
 
+       /**
+        * @dataProvider provideIsMovable
+        * @covers Title::isMovable
+        *
+        * @param string|Title $title
+        * @param bool $expected
+        * @param callable|null $hookCallback For TitleIsMovable
+        */
+       public function testIsMovable( $title, $expected, $hookCallback = null ) {
+               if ( $hookCallback ) {
+                       $this->setTemporaryHook( 'TitleIsMovable', $hookCallback );
+               }
+               if ( is_string( $title ) ) {
+                       $title = Title::newFromText( $title );
+               }
+
+               $this->assertSame( $expected, $title->isMovable() );
+       }
+
+       public static function provideIsMovable() {
+               return [
+                       'Simple title' => [ 'Foo', true ],
+                       // @todo Should these next two really be true?
+                       'Empty name' => [ Title::makeTitle( NS_MAIN, '' ), true ],
+                       'Invalid name' => [ Title::makeTitle( NS_MAIN, '<' ), true ],
+                       'Interwiki' => [ Title::makeTitle( NS_MAIN, 'Test', '', 'otherwiki' ), false ],
+                       'Special page' => [ 'Special:FooBar', false ],
+                       'Aborted by hook' => [ 'Hooked in place', false,
+                               function ( Title $title, &$result ) {
+                                       $result = false;
+                               }
+                       ],
+               ];
+       }
+
        public function provideCreateFragmentTitle() {
                return [
                        [ Title::makeTitle( NS_MAIN, 'Test' ), 'foo' ],
@@ -1288,10 +1277,11 @@ class TitleTest extends MediaWikiTestCase {
         * @covers Title::newMainPage
         */
        public function testNewMainPage() {
-               $msgCache = TestingAccessWrapper::newFromClass( MessageCache::class );
-               $msgCache->instance = $this->createMock( MessageCache::class );
-               $msgCache->instance->method( 'get' )->willReturn( 'Foresheet' );
-               $msgCache->instance->method( 'transform' )->willReturn( 'Foresheet' );
+               $mock = $this->createMock( MessageCache::class );
+               $mock->method( 'get' )->willReturn( 'Foresheet' );
+               $mock->method( 'transform' )->willReturn( 'Foresheet' );
+
+               $this->setService( 'MessageCache', $mock );
 
                $this->assertSame(
                        'Foresheet',