MovePageTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @group Database
  4. */
  5. class MovePageTest extends MediaWikiTestCase {
  6. /**
  7. * @dataProvider provideIsValidMove
  8. * @covers MovePage::isValidMove
  9. * @covers MovePage::isValidFileMove
  10. */
  11. public function testIsValidMove( $old, $new, $error ) {
  12. $this->setMwGlobals( 'wgContentHandlerUseDB', false );
  13. $mp = new MovePage(
  14. Title::newFromText( $old ),
  15. Title::newFromText( $new )
  16. );
  17. $status = $mp->isValidMove();
  18. if ( $error === true ) {
  19. $this->assertTrue( $status->isGood() );
  20. } else {
  21. $this->assertTrue( $status->hasMessage( $error ) );
  22. }
  23. }
  24. /**
  25. * This should be kept in sync with TitleTest::provideTestIsValidMoveOperation
  26. */
  27. public static function provideIsValidMove() {
  28. return [
  29. // for MovePage::isValidMove
  30. [ 'Test', 'Test', 'selfmove' ],
  31. [ 'Special:FooBar', 'Test', 'immobile-source-namespace' ],
  32. [ 'Test', 'Special:FooBar', 'immobile-target-namespace' ],
  33. [ 'MediaWiki:Common.js', 'Help:Some wikitext page', 'bad-target-model' ],
  34. [ 'Page', 'File:Test.jpg', 'nonfile-cannot-move-to-file' ],
  35. // for MovePage::isValidFileMove
  36. [ 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ],
  37. ];
  38. }
  39. /**
  40. * Integration test to catch regressions like T74870. Taken and modified
  41. * from SemanticMediaWiki
  42. *
  43. * @covers Title::moveTo
  44. */
  45. public function testTitleMoveCompleteIntegrationTest() {
  46. $oldTitle = Title::newFromText( 'Help:Some title' );
  47. WikiPage::factory( $oldTitle )->doEditContent( new WikitextContent( 'foo' ), 'bar' );
  48. $newTitle = Title::newFromText( 'Help:Some other title' );
  49. $this->assertNull(
  50. WikiPage::factory( $newTitle )->getRevision()
  51. );
  52. $this->assertTrue( $oldTitle->moveTo( $newTitle, false, 'test1', true ) );
  53. $this->assertNotNull(
  54. WikiPage::factory( $oldTitle )->getRevision()
  55. );
  56. $this->assertNotNull(
  57. WikiPage::factory( $newTitle )->getRevision()
  58. );
  59. }
  60. }