]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - tests/phpunit/includes/MovePageTest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / tests / phpunit / includes / MovePageTest.php
1 <?php
2
3 /**
4  * @group Database
5  */
6 class MovePageTest extends MediaWikiTestCase {
7
8         /**
9          * @dataProvider provideIsValidMove
10          * @covers MovePage::isValidMove
11          * @covers MovePage::isValidFileMove
12          */
13         public function testIsValidMove( $old, $new, $error ) {
14                 $this->setMwGlobals( 'wgContentHandlerUseDB', false );
15                 $mp = new MovePage(
16                         Title::newFromText( $old ),
17                         Title::newFromText( $new )
18                 );
19                 $status = $mp->isValidMove();
20                 if ( $error === true ) {
21                         $this->assertTrue( $status->isGood() );
22                 } else {
23                         $this->assertTrue( $status->hasMessage( $error ) );
24                 }
25         }
26
27         /**
28          * This should be kept in sync with TitleTest::provideTestIsValidMoveOperation
29          */
30         public static function provideIsValidMove() {
31                 return [
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' ],
40                 ];
41         }
42
43         /**
44          * Integration test to catch regressions like T74870. Taken and modified
45          * from SemanticMediaWiki
46          */
47         public function testTitleMoveCompleteIntegrationTest() {
48                 $oldTitle = Title::newFromText( 'Help:Some title' );
49                 WikiPage::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
50                 $newTitle = Title::newFromText( 'Help:Some other title' );
51                 $this->assertNull(
52                         WikiPage::factory( $newTitle )->getRevision()
53                 );
54
55                 $this->assertTrue( $oldTitle->moveTo( $newTitle, false, 'test1', true ) );
56                 $this->assertNotNull(
57                         WikiPage::factory( $oldTitle )->getRevision()
58                 );
59                 $this->assertNotNull(
60                         WikiPage::factory( $newTitle )->getRevision()
61                 );
62         }
63 }