3 namespace MediaWiki\Tests\Specials
;
6 use MediaWiki\MainConfigNames
;
7 use MediaWiki\Title\Title
;
8 use SpecialPageTestBase
;
11 * @covers \MediaWiki\Specials\SpecialMovePage
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',
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",
57 'The subpages list was not properly truncated.'
60 $this->assertStringContainsString(
63 'The the subpage message should have been shown'
65 $this->assertStringNotContainsString(
66 'movesubpagetext-truncated',
68 'The the subpage message should have been shown'
73 public static function provideLoadFormForOldTitleWithSubpages() {
75 '1 subpage, max subpages at 2' => [ 1, 2, false ],
76 '3 subpages, max subpages at 2' => [ 3, 2, true ],