6 class MovePageTest
extends MediaWikiTestCase
{
9 * @dataProvider provideIsValidMove
10 * @covers MovePage::isValidMove
11 * @covers MovePage::isValidFileMove
13 public function testIsValidMove( $old, $new, $error ) {
14 $this->setMwGlobals( 'wgContentHandlerUseDB', false );
16 Title
::newFromText( $old ),
17 Title
::newFromText( $new )
19 $status = $mp->isValidMove();
20 if ( $error === true ) {
21 $this->assertTrue( $status->isGood() );
23 $this->assertTrue( $status->hasMessage( $error ) );
28 * This should be kept in sync with TitleTest::provideTestIsValidMoveOperation
30 public static function provideIsValidMove() {
32 // for MovePage::isValidMove
33 [ 'Test', 'Test', 'selfmove' ],
34 [ 'Special:FooBar', 'Test', 'immobile-source-namespace' ],
35 [ 'Test', 'Special:FooBar', 'immobile-target-namespace' ],
36 [ 'MediaWiki:Common.js', 'Help:Some wikitext page', 'bad-target-model' ],
37 [ 'Page', 'File:Test.jpg', 'nonfile-cannot-move-to-file' ],
38 // for MovePage::isValidFileMove
39 [ 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ],
44 * Integration test to catch regressions like T74870. Taken and modified
45 * from SemanticMediaWiki
47 * @covers Title::moveTo
49 public function testTitleMoveCompleteIntegrationTest() {
50 $oldTitle = Title
::newFromText( 'Help:Some title' );
51 WikiPage
::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
52 $newTitle = Title
::newFromText( 'Help:Some other title' );
54 WikiPage
::factory( $newTitle )->getRevision()
57 $this->assertTrue( $oldTitle->moveTo( $newTitle, false, 'test1', true ) );
59 WikiPage
::factory( $oldTitle )->getRevision()
62 WikiPage
::factory( $newTitle )->getRevision()
67 * Test for the move operation being aborted via the TitleMove hook
69 public function testMoveAbortedByTitleMoveHook() {
70 $error = 'Preventing move operation with TitleMove hook.';
71 $this->setTemporaryHook( 'TitleMove',
72 function ( $old, $new, $user, $reason, $status ) use ( $error ) {
73 $status->fatal( $error );
77 $oldTitle = Title
::newFromText( 'Some old title' );
78 WikiPage
::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
79 $newTitle = Title
::newFromText( 'A brand new title' );
80 $mp = new MovePage( $oldTitle, $newTitle );
81 $user = User
::newFromName( 'TitleMove tester' );
82 $status = $mp->move( $user, 'Reason', true );
83 $this->assertTrue( $status->hasMessage( $error ) );