Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / UndeleteTest.php
blob92dec884f2b99711017e33a3286ecf75e2a34a9e
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait;
6 use Undelete;
8 /**
9 * @covers \Undelete
10 * @group Database
11 * @author Dreamy Jazz
13 class UndeleteTest extends MaintenanceBaseTestCase {
14 use MockAuthorityTrait;
16 protected function getMaintenanceClass() {
17 return Undelete::class;
20 public function testExecute() {
21 // Create a page and then delete it
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 // Call ::execute
30 $this->maintenance->setArg( 'pagename', $testPage );
31 $this->maintenance->execute();
32 // Verify that the page was undeleted.
33 $testPage->clear();
34 $this->assertTrue( $testPage->exists() );
35 $this->expectOutputString(
36 "Undeleting " . $testPage->getTitle()->getPrefixedDBkey() . "...\n" .
37 "done\n"
41 public function testEmailResetOnInvalidTitle() {
42 $this->expectCallToFatalError();
43 $this->expectOutputRegex( "/Invalid title/" );
44 $this->maintenance->setArg( 0, ':::' );
45 $this->maintenance->execute();
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();
56 public function testExecuteForPageWithNoDeletedRevisions() {
57 $this->expectCallToFatalError();
58 $this->expectOutputRegex( '/No matching pages found in the deletion archive/' );
59 // Create a page and then delete it
60 $testPage = $this->getExistingTestPage();
61 // Call ::execute
62 $this->maintenance->setArg( 'pagename', $testPage );
63 $this->maintenance->execute();