Merge "Drop cache interwiki"
[mediawiki.git] / tests / phpunit / includes / specials / SpecialMovePageTest.php
blob187e79dda3c02b2b8ae31b5c347b576bf54d1085
1 <?php
3 namespace MediaWiki\Tests\Specials;
5 use ErrorPageError;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\Title\Title;
8 use SpecialPageTestBase;
10 /**
11 * @covers \MediaWiki\Specials\SpecialMovePage
12 * @group Database
14 class SpecialMovePageTest extends SpecialPageTestBase {
16 protected function newSpecialPage() {
17 return $this->getServiceContainer()->getSpecialPageFactory()->getPage( 'Movepage' );
20 public function testNoDefinedOldTitle() {
21 $this->expectException( ErrorPageError::class );
22 // The expected exception message will be in English because of T46111
23 $this->expectExceptionMessage( wfMessage( 'notargettext' )->inLanguage( 'en' )->text() );
24 $this->executeSpecialPage( '', null, null, $this->getTestSysop()->getUser() );
27 public function testOldTitleDoesNotExist() {
28 $this->expectException( ErrorPageError::class );
29 // The expected exception message will be in English because of T46111
30 $this->expectExceptionMessage( wfMessage( 'nopagetext' )->inLanguage( 'en' )->text() );
31 $this->executeSpecialPage( $this->getNonexistingTestPage()->getTitle(), null, null, $this->getTestSysop()->getUser() );
34 /** @dataProvider provideLoadFormForOldTitleWithSubpages */
35 public function testLoadFormForOldTitleWithSubpages( $subpageCount, $maximumMovedPages, $shouldShowLimitedMessage ) {
36 // Tests that the security patch for T357760 works.
37 $this->overrideConfigValue( MainConfigNames::MaximumMovedPages, $maximumMovedPages );
38 // NS_TALK supports subpages, so we can use that namespace for testing.
39 $testPage = $this->getExistingTestPage( Title::newFromText( 'Test page for old title', NS_TALK ) );
40 // Create a few testing subpages
41 for ( $i = 0; $i < $subpageCount; $i++ ) {
42 $this->getExistingTestPage( Title::newFromText( "Test page for old title/$i", NS_TALK ) );
44 // Load Special:MovePage with $testPage as the old title
45 [ $html ] = $this->executeSpecialPage( $testPage->getTitle(), null, 'qqx', $this->getTestSysop()->getUser() );
46 if ( $shouldShowLimitedMessage ) {
47 $this->assertStringContainsString(
48 'movesubpagetext-truncated',
49 $html,
50 'The the truncated subpage message should have been shown'
52 // This works because the subpages start from 0 and increase by 1. As such, the subpage with the number in
53 // $maximumMovedPages will not be displayed (because it would cause the limit to be broken).
54 $this->assertStringNotContainsString(
55 "Talk:Test_page_for_old_title/$maximumMovedPages",
56 $html,
57 'The subpages list was not properly truncated.'
59 } else {
60 $this->assertStringContainsString(
61 'movesubpagetext',
62 $html,
63 'The the subpage message should have been shown'
65 $this->assertStringNotContainsString(
66 'movesubpagetext-truncated',
67 $html,
68 'The the subpage message should have been shown'
73 public static function provideLoadFormForOldTitleWithSubpages() {
74 return [
75 '1 subpage, max subpages at 2' => [ 1, 2, false ],
76 '3 subpages, max subpages at 2' => [ 3, 2, true ],