]
]
] );
-
- // Reset services since we modified $wgLocalInterwikis
- $this->overrideMwServices();
}
/**
];
}
- /**
- * 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 ) {
- global $wgMultiContentRevisionSchemaMigrationStage;
-
- $this->hideDeprecated( 'Title::isValidMoveOperation' );
-
- 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 );
- if ( $expected === true ) {
- $this->assertTrue( $errors );
- } else {
- $errors = $this->flattenErrorsArray( $errors );
- foreach ( (array)$expected as $error ) {
- $this->assertContains( $error, $errors );
- }
- }
- }
-
- public static function provideTestIsValidMoveOperation() {
- global $wgMultiContentRevisionSchemaMigrationStage;
- $ret = [
- // for Title::isValidMoveOperation
- [ 'Some page', '', 'badtitletext' ],
- [ 'Test', 'Test', 'selfmove' ],
- [ 'Special:FooBar', 'Test', 'immobile-source-namespace' ],
- [ 'Test', 'Special:FooBar', 'immobile-target-namespace' ],
- [ '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;
- }
-
/**
* Auth-less test of Title::userCan
*
$this->assertEquals(
false,
$title->exists(),
- 'exists() should rely on link cache unless GAID_FOR_UPDATE is used'
+ 'exists() should rely on link cache unless READ_LATEST is used'
);
$this->assertEquals(
true,
- $title->exists( Title::GAID_FOR_UPDATE ),
- 'exists() should re-query database when GAID_FOR_UPDATE is used'
+ $title->exists( Title::READ_LATEST ),
+ 'exists() should re-query database when READ_LATEST is used'
);
}
return [
[ Title::makeTitle( NS_SPECIAL, 'Test' ) ],
[ Title::makeTitle( NS_MEDIA, 'Test' ) ],
- [ Title::makeTitle( NS_MAIN, '', 'Kittens' ) ],
- [ Title::makeTitle( NS_MAIN, 'Kittens', '', 'acme' ) ],
+ ];
+ }
+
+ public static function provideGetTalkPage_broken() {
+ // These cases *should* be bad, but are not treated as bad, for backwards compatibility.
+ // See discussion on T227817.
+ return [
+ [
+ Title::makeTitle( NS_MAIN, '', 'Kittens' ),
+ Title::makeTitle( NS_TALK, '' ), // Section is lost!
+ false,
+ ],
+ [
+ Title::makeTitle( NS_MAIN, 'Kittens', '', 'acme' ),
+ Title::makeTitle( NS_TALK, 'Kittens', '' ), // Interwiki prefix is lost!
+ true,
+ ],
];
}
$title->getTalkPage();
}
+ /**
+ * @dataProvider provideGetTalkPage_broken
+ * @covers Title::getTalkPageIfDefined
+ */
+ public function testGetTalkPage_broken( Title $title, Title $expected, $valid ) {
+ $errorLevel = error_reporting( E_ERROR );
+
+ // NOTE: Eventually we want to throw in this case. But while there is still code that
+ // calls this method without checking, we want to avoid fatal errors.
+ // See discussion on T227817.
+ $result = $title->getTalkPage();
+ $this->assertTrue( $expected->equals( $result ) );
+ $this->assertSame( $valid, $result->isValid() );
+
+ error_reporting( $errorLevel );
+ }
+
/**
* @dataProvider provideGetTalkPage_good
* @covers Title::getTalkPageIfDefined
$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' ],