| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait; |
| 6 |
use Undelete; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class UndeleteTest extends MaintenanceBaseTestCase { |
| 14 |
use MockAuthorityTrait; |
| 15 |
|
| 16 |
protected function getMaintenanceClass() { |
| 17 |
return Undelete::class; |
| 18 |
} |
| 19 |
|
| 20 |
public function testExecute() { |
| 21 |
|
| 22 |
$testPage = $this->getExistingTestPage(); |
| 23 |
$deleteStatus = $this->getServiceContainer()->getDeletePageFactory() |
| 24 |
->newDeletePage( $testPage, $this->mockRegisteredUltimateAuthority() ) |
| 25 |
->deleteIfAllowed( 'test' ); |
| 26 |
$this->assertStatusGood( $deleteStatus ); |
| 27 |
$testPage->clear(); |
| 28 |
$this->assertFalse( $testPage->exists() ); |
| 29 |
|
| 30 |
$this->maintenance->setArg( 'pagename', $testPage ); |
| 31 |
$this->maintenance->execute(); |
| 32 |
|
| 33 |
$testPage->clear(); |
| 34 |
$this->assertTrue( $testPage->exists() ); |
| 35 |
$this->expectOutputString( |
| 36 |
"Undeleting " . $testPage->getTitle()->getPrefixedDBkey() . "...\n" . |
| 37 |
"done\n" |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
public function testEmailResetOnInvalidTitle() { |
| 42 |
$this->expectCallToFatalError(); |
| 43 |
$this->expectOutputRegex( "/Invalid title/" ); |
| 44 |
$this->maintenance->setArg( 0, ':::' ); |
| 45 |
$this->maintenance->execute(); |
| 46 |
} |
| 47 |
|
| 48 |
public function testEmailResetOnInvalidUsername() { |
| 49 |
$this->expectCallToFatalError(); |
| 50 |
$this->expectOutputRegex( "/Invalid username/" ); |
| 51 |
$this->maintenance->setArg( 0, $this->getNonexistingTestPage() ); |
| 52 |
$this->maintenance->setOption( 'user', 'Template:Testing#test' ); |
| 53 |
$this->maintenance->execute(); |
| 54 |
} |
| 55 |
|
| 56 |
public function testExecuteForPageWithNoDeletedRevisions() { |
| 57 |
$this->expectCallToFatalError(); |
| 58 |
$this->expectOutputRegex( '/No matching pages found in the deletion archive/' ); |
| 59 |
|
| 60 |
$testPage = $this->getExistingTestPage(); |
| 61 |
|
| 62 |
$this->maintenance->setArg( 'pagename', $testPage ); |
| 63 |
$this->maintenance->execute(); |
| 64 |
} |
| 65 |
} |