| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Specials; |
| 4 |
|
| 5 |
use ErrorPageError; |
| 6 |
use MediaWiki\MainConfigNames; |
| 7 |
use MediaWiki\Title\Title; |
| 8 |
use SpecialPageTestBase; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class SpecialMovePageTest extends SpecialPageTestBase { |
| 15 |
|
| 16 |
protected function newSpecialPage() { |
| 17 |
return $this->getServiceContainer()->getSpecialPageFactory()->getPage( 'Movepage' ); |
| 18 |
} |
| 19 |
|
| 20 |
public function testNoDefinedOldTitle() { |
| 21 |
$this->expectException( ErrorPageError::class ); |
| 22 |
|
| 23 |
$this->expectExceptionMessage( wfMessage( 'notargettext' )->inLanguage( 'en' )->text() ); |
| 24 |
$this->executeSpecialPage( '', null, null, $this->getTestSysop()->getUser() ); |
| 25 |
} |
| 26 |
|
| 27 |
public function testOldTitleDoesNotExist() { |
| 28 |
$this->expectException( ErrorPageError::class ); |
| 29 |
|
| 30 |
$this->expectExceptionMessage( wfMessage( 'nopagetext' )->inLanguage( 'en' )->text() ); |
| 31 |
$this->executeSpecialPage( $this->getNonexistingTestPage()->getTitle(), null, null, $this->getTestSysop()->getUser() ); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
public function testLoadFormForOldTitleWithSubpages( $subpageCount, $maximumMovedPages, $shouldShowLimitedMessage ) { |
| 36 |
|
| 37 |
$this->overrideConfigValue( MainConfigNames::MaximumMovedPages, $maximumMovedPages ); |
| 38 |
|
| 39 |
$testPage = $this->getExistingTestPage( Title::newFromText( 'Test page for old title', NS_TALK ) ); |
| 40 |
|
| 41 |
for ( $i = 0; $i < $subpageCount; $i++ ) { |
| 42 |
$this->getExistingTestPage( Title::newFromText( "Test page for old title/$i", NS_TALK ) ); |
| 43 |
} |
| 44 |
|
| 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' |
| 51 |
); |
| 52 |
|
| 53 |
|
| 54 |
$this->assertStringNotContainsString( |
| 55 |
"Talk:Test_page_for_old_title/$maximumMovedPages", |
| 56 |
$html, |
| 57 |
'The subpages list was not properly truncated.' |
| 58 |
); |
| 59 |
} else { |
| 60 |
$this->assertStringContainsString( |
| 61 |
'movesubpagetext', |
| 62 |
$html, |
| 63 |
'The the subpage message should have been shown' |
| 64 |
); |
| 65 |
$this->assertStringNotContainsString( |
| 66 |
'movesubpagetext-truncated', |
| 67 |
$html, |
| 68 |
'The the subpage message should have been shown' |
| 69 |
); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 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 ], |
| 77 |
]; |
| 78 |
} |
| 79 |
} |