use MediaWiki\Interwiki\InterwikiLookup;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
-use Wikimedia\TestingAccessWrapper;
/**
* @group Database
$this->setContentLang( 'en' );
}
- protected function tearDown() {
- // For testNewMainPage
- MessageCache::destroyInstance();
- parent::tearDown();
- }
-
/**
* @covers Title::legalChars
*/
];
}
- /**
- * 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
*
$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' ],
* @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',