X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FMovePageTest.php;h=9166666543fce0eaa749be94f5a02806ee017aa5;hb=ac4f78fa1398d7fd4d5dbb0565f1d9abbaf5baf0;hp=1b2b159f0a025f52e8dd92b7e3b29837741e5b31;hpb=f1b6abffc281cfac3a294ce6c4288c070a686de1;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/MovePageTest.php b/tests/phpunit/includes/MovePageTest.php index 1b2b159f0a..9166666543 100644 --- a/tests/phpunit/includes/MovePageTest.php +++ b/tests/phpunit/includes/MovePageTest.php @@ -5,6 +5,13 @@ */ class MovePageTest extends MediaWikiTestCase { + public function setUp() { + parent::setUp(); + $this->tablesUsed[] = 'page'; + $this->tablesUsed[] = 'revision'; + $this->tablesUsed[] = 'comment'; + } + /** * @dataProvider provideIsValidMove * @covers MovePage::isValidMove @@ -40,29 +47,6 @@ class MovePageTest extends MediaWikiTestCase { ]; } - /** - * Integration test to catch regressions like T74870. Taken and modified - * from SemanticMediaWiki - * - * @covers Title::moveTo - */ - 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( - WikiPage::factory( $newTitle )->getRevision() - ); - } - /** * Test for the move operation being aborted via the TitleMove hook * @covers MovePage::move @@ -83,4 +67,108 @@ class MovePageTest extends MediaWikiTestCase { $status = $mp->move( $user, 'Reason', true ); $this->assertTrue( $status->hasMessage( $error ) ); } + + /** + * Test moving subpages from one page to another + * @covers MovePage::moveSubpages + */ + public function testMoveSubpages() { + $name = ucfirst( __FUNCTION__ ); + + $subPages = [ "Talk:$name/1", "Talk:$name/2" ]; + $ids = []; + $pages = [ + $name, + "Talk:$name", + "$name 2", + "Talk:$name 2", + ]; + foreach ( array_merge( $pages, $subPages ) as $page ) { + $ids[$page] = $this->createPage( $page ); + } + + $oldTitle = Title::newFromText( "Talk:$name" ); + $newTitle = Title::newFromText( "Talk:$name 2" ); + $mp = new MovePage( $oldTitle, $newTitle ); + $status = $mp->moveSubpages( $this->getTestUser()->getUser(), 'Reason', true ); + + $this->assertTrue( $status->isGood(), + "Moving subpages from Talk:{$name} to Talk:{$name} 2 was not completely successful." ); + foreach ( $subPages as $page ) { + $this->assertMoved( $page, str_replace( $name, "$name 2", $page ), $ids[$page] ); + } + } + + /** + * Test moving subpages from one page to another + * @covers MovePage::moveSubpagesIfAllowed + */ + public function testMoveSubpagesIfAllowed() { + $name = ucfirst( __FUNCTION__ ); + + $subPages = [ "Talk:$name/1", "Talk:$name/2" ]; + $ids = []; + $pages = [ + $name, + "Talk:$name", + "$name 2", + "Talk:$name 2", + ]; + foreach ( array_merge( $pages, $subPages ) as $page ) { + $ids[$page] = $this->createPage( $page ); + } + + $oldTitle = Title::newFromText( "Talk:$name" ); + $newTitle = Title::newFromText( "Talk:$name 2" ); + $mp = new MovePage( $oldTitle, $newTitle ); + $status = $mp->moveSubpagesIfAllowed( $this->getTestUser()->getUser(), 'Reason', true ); + + $this->assertTrue( $status->isGood(), + "Moving subpages from Talk:{$name} to Talk:{$name} 2 was not completely successful." ); + foreach ( $subPages as $page ) { + $this->assertMoved( $page, str_replace( $name, "$name 2", $page ), $ids[$page] ); + } + } + + /** + * Shortcut function to create a page and return its id. + * + * @param string $name Page to create + * @return int ID of created page + */ + protected function createPage( $name ) { + return $this->editPage( $name, 'Content' )->value['revision']->getPage(); + } + + /** + * @param string $from Prefixed name of source + * @param string $to Prefixed name of destination + * @param string $id Page id of the page to move + * @param array|string|null $opts Options: 'noredirect' to expect no redirect + */ + protected function assertMoved( $from, $to, $id, $opts = null ) { + $opts = (array)$opts; + + Title::clearCaches(); + $fromTitle = Title::newFromText( $from ); + $toTitle = Title::newFromText( $to ); + + $this->assertTrue( $toTitle->exists(), + "Destination {$toTitle->getPrefixedText()} does not exist" ); + + if ( in_array( 'noredirect', $opts ) ) { + $this->assertFalse( $fromTitle->exists(), + "Source {$fromTitle->getPrefixedText()} exists" ); + } else { + $this->assertTrue( $fromTitle->exists(), + "Source {$fromTitle->getPrefixedText()} does not exist" ); + $this->assertTrue( $fromTitle->isRedirect(), + "Source {$fromTitle->getPrefixedText()} is not a redirect" ); + + $target = Revision::newFromTitle( $fromTitle )->getContent()->getRedirectTarget(); + $this->assertSame( $toTitle->getPrefixedText(), $target->getPrefixedText() ); + } + + $this->assertSame( $id, $toTitle->getArticleID() ); + } }