Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / DeleteDefaultMessagesTest.php
blob5c0e88cefd2de379b9a7c37af7bc497b41ed786c
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use DeleteDefaultMessages;
6 use TestUser;
7 use Wikimedia\Rdbms\IDBAccessObject;
9 /**
10 * @covers \DeleteDefaultMessages
11 * @group Database
12 * @author Dreamy Jazz
14 class DeleteDefaultMessagesTest extends MaintenanceBaseTestCase {
16 protected function getMaintenanceClass() {
17 return DeleteDefaultMessages::class;
20 private function performMediaWikiDefaultEdit( $title, $content ) {
21 $this->editPage(
22 $title, $content, 'test', NS_MEDIAWIKI,
23 $this->getServiceContainer()->getUserFactory()->newFromName( 'MediaWiki default' )
27 public function testExecuteForNoRelevantPages() {
28 $this->maintenance->execute();
29 $this->expectOutputString( "Checking existence of old default messages...done.\n" );
32 public function testExecuteWhenNoMessagesLastEditedByMediaWikiDefault() {
33 // Create MediaWiki:Edit with two revisions, with the latest not edited by MediaWiki default.
34 $this->performMediaWikiDefaultEdit( 'MediaWiki:Edit', 'test-1234' );
35 $this->editPage(
36 'MediaWiki:Edit', 'testing-content', 'test', NS_MEDIAWIKI,
37 $this->getTestUser()->getAuthority()
39 $this->testExecuteForNoRelevantPages();
40 $this->assertTrue(
41 $this->getServiceContainer()->getTitleFactory()->newFromText( 'MediaWiki:Edit' )->exists(),
42 'MediaWiki:Edit was deleted when it should not have been.'
46 public function testExecuteForDryRun() {
47 // Create MediaWiki:Edit with two revisions by MediaWiki default, and MediaWiki:Hist with one revision by
48 // MediaWiki default.
49 $this->performMediaWikiDefaultEdit( 'MediaWiki:Edit', 'test-1234' );
50 $this->performMediaWikiDefaultEdit( 'MediaWiki:Edit', 'test-12345' );
51 $this->performMediaWikiDefaultEdit( 'MediaWiki:Hist', 'testing-1234' );
52 // Run with 'dry-run' set.
53 $this->maintenance->setOption( 'dry-run', 1 );
54 $this->maintenance->execute();
55 $this->assertTrue(
56 $this->getServiceContainer()->getTitleFactory()->newFromText( 'MediaWiki:Edit' )->exists(),
57 'MediaWiki:Edit was deleted on a dry run.'
59 $this->assertTrue(
60 $this->getServiceContainer()->getTitleFactory()->newFromText( 'MediaWiki:Hist' )->exists(),
61 'MediaWiki:Hist was deleted on a dry run.'
63 $this->expectOutputRegex(
64 "/.*\n.*MediaWiki:Edit.*\n.*MediaWiki:Hist.*\n\nRun again without --dry-run to delete these pages.\n/"
68 public function testExecute() {
69 // Create MediaWiki:Edit with two revisions by MediaWiki default, and MediaWiki:Hist with one revision by
70 // MediaWiki default.
71 $editMessagePage = $this->getServiceContainer()->getTitleFactory()->newFromText( 'MediaWiki:Edit' );
72 $histMessagePage = $this->getServiceContainer()->getTitleFactory()->newFromText( 'MediaWiki:Hist' );
73 $diffMessagePage = $this->getServiceContainer()->getTitleFactory()->newFromText( 'MediaWiki:Diff' );
74 $this->performMediaWikiDefaultEdit( $editMessagePage, 'test-1234' );
75 $this->performMediaWikiDefaultEdit( $editMessagePage, 'test-12345' );
76 $this->performMediaWikiDefaultEdit( $histMessagePage, 'testing-1234' );
77 // Create a MediaWiki page which should not be deleted.
78 $this->editPage(
79 $diffMessagePage, 'testing-content', 'test', NS_MEDIAWIKI,
80 $this->getTestUser()->getAuthority()
82 // Run ::execute to actually delete pages.
83 $this->maintenance->execute();
84 // Verify that only the correct pages have been deleted.
85 $this->assertFalse(
86 $editMessagePage->exists( IDBAccessObject::READ_LATEST ), 'MediaWiki:Edit should have been deleted.'
88 $this->assertFalse(
89 $histMessagePage->exists( IDBAccessObject::READ_LATEST ), 'MediaWiki:Hist should have been deleted.'
91 $this->assertTrue(
92 $diffMessagePage->exists( IDBAccessObject::READ_LATEST ), 'MediaWiki:Diff should not have been deleted.'
94 $this->expectOutputRegex(
95 "/Checking existence of old default messages\.\.\.\n" .
96 "\.\.\.deleting old default messages.*done!\n/"
100 public function addDBData() {
101 // Create the MediaWiki default user for each test.
102 new TestUser( 'MediaWiki default' );