3 namespace MediaWiki\Tests\Maintenance
;
5 use DeleteDefaultMessages
;
7 use Wikimedia\Rdbms\IDBAccessObject
;
10 * @covers \DeleteDefaultMessages
14 class DeleteDefaultMessagesTest
extends MaintenanceBaseTestCase
{
16 protected function getMaintenanceClass() {
17 return DeleteDefaultMessages
::class;
20 private function performMediaWikiDefaultEdit( $title, $content ) {
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' );
36 'MediaWiki:Edit', 'testing-content', 'test', NS_MEDIAWIKI
,
37 $this->getTestUser()->getAuthority()
39 $this->testExecuteForNoRelevantPages();
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
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();
56 $this->getServiceContainer()->getTitleFactory()->newFromText( 'MediaWiki:Edit' )->exists(),
57 'MediaWiki:Edit was deleted on a dry run.'
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
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.
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.
86 $editMessagePage->exists( IDBAccessObject
::READ_LATEST
), 'MediaWiki:Edit should have been deleted.'
89 $histMessagePage->exists( IDBAccessObject
::READ_LATEST
), 'MediaWiki:Hist should have been deleted.'
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' );