2014-09-19 19:10:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
2015-02-05 18:52:10 +00:00
|
|
|
/**
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
2014-09-19 19:10:53 +00:00
|
|
|
class MovePageTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideIsValidMove
|
|
|
|
|
* @covers MovePage::isValidMove
|
|
|
|
|
* @covers MovePage::isValidFileMove
|
|
|
|
|
*/
|
|
|
|
|
public function testIsValidMove( $old, $new, $error ) {
|
|
|
|
|
$this->setMwGlobals( 'wgContentHandlerUseDB', false );
|
|
|
|
|
$mp = new MovePage(
|
|
|
|
|
Title::newFromText( $old ),
|
|
|
|
|
Title::newFromText( $new )
|
|
|
|
|
);
|
|
|
|
|
$status = $mp->isValidMove();
|
|
|
|
|
if ( $error === true ) {
|
|
|
|
|
$this->assertTrue( $status->isGood() );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertTrue( $status->hasMessage( $error ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This should be kept in sync with TitleTest::provideTestIsValidMoveOperation
|
|
|
|
|
*/
|
|
|
|
|
public static function provideIsValidMove() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-19 19:10:53 +00:00
|
|
|
// for MovePage::isValidMove
|
2016-02-17 09:09:32 +00:00
|
|
|
[ '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' ],
|
2014-09-19 19:10:53 +00:00
|
|
|
// for MovePage::isValidFileMove
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ],
|
|
|
|
|
];
|
2014-09-19 19:10:53 +00:00
|
|
|
}
|
2015-02-05 18:52:10 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Integration test to catch regressions like T74870. Taken and modified
|
|
|
|
|
* from SemanticMediaWiki
|
2018-05-07 08:22:40 +00:00
|
|
|
*
|
|
|
|
|
* @covers Title::moveTo
|
2015-02-05 18:52:10 +00:00
|
|
|
*/
|
|
|
|
|
public function testTitleMoveCompleteIntegrationTest() {
|
|
|
|
|
$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(
|
2015-06-16 19:06:19 +00:00
|
|
|
WikiPage::factory( $newTitle )->getRevision()
|
2015-02-05 18:52:10 +00:00
|
|
|
);
|
|
|
|
|
}
|
2018-11-08 15:02:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test for the move operation being aborted via the TitleMove hook
|
|
|
|
|
*/
|
|
|
|
|
public function testMoveAbortedByTitleMoveHook() {
|
|
|
|
|
$error = 'Preventing move operation with TitleMove hook.';
|
|
|
|
|
$this->setTemporaryHook( 'TitleMove',
|
|
|
|
|
function ( $old, $new, $user, $reason, $status ) use ( $error ) {
|
|
|
|
|
$status->fatal( $error );
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$oldTitle = Title::newFromText( 'Some old title' );
|
|
|
|
|
WikiPage::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
|
|
|
|
|
$newTitle = Title::newFromText( 'A brand new title' );
|
|
|
|
|
$mp = new MovePage( $oldTitle, $newTitle );
|
|
|
|
|
$user = User::newFromName( 'TitleMove tester' );
|
|
|
|
|
$status = $mp->move( $user, 'Reason', true );
|
|
|
|
|
$this->assertTrue( $status->hasMessage( $error ) );
|
|
|
|
|
}
|
2014-09-19 19:10:53 +00:00
|
|
|
}
|