3 namespace MediaWiki\Tests\Maintenance
;
5 use DeleteArchivedRevisions
;
6 use MediaWiki\Tests\Unit\Permissions\MockAuthorityTrait
;
9 * @covers \DeleteArchivedRevisions
13 class DeleteArchivedRevisionsTest
extends MaintenanceBaseTestCase
{
14 use MockAuthorityTrait
;
16 protected function getMaintenanceClass() {
17 return DeleteArchivedRevisions
::class;
20 /** @dataProvider provideExecute */
21 public function testExecute( $options, $expectedRowCountAfterExecution, $expectedOutputRegex ) {
22 // Create a page and then delete it
23 $testPage = $this->getExistingTestPage();
24 $deleteStatus = $this->getServiceContainer()->getDeletePageFactory()
25 ->newDeletePage( $testPage, $this->mockRegisteredUltimateAuthority() )
26 ->deleteIfAllowed( 'test' );
27 $this->assertStatusGood( $deleteStatus );
28 // Check that this has caused a revision to be added to the archive table
29 $this->newSelectQueryBuilder()
30 ->select( 'COUNT(*)' )
32 ->assertFieldValue( 1 );
34 foreach ( $options as $name => $value ) {
35 $this->maintenance
->setOption( $name, $value );
37 $this->maintenance
->execute();
38 // Verify that the archive table is now empty.
39 $this->newSelectQueryBuilder()
40 ->select( 'COUNT(*)' )
42 ->assertFieldValue( $expectedRowCountAfterExecution );
43 $this->expectOutputRegex( $expectedOutputRegex );
46 public static function provideExecute() {
48 'Dry-run' => [ [], 1, '/Found 1 revisions to delete/' ],
49 'Actual deletion' => [ [ 'delete' => 1 ], 0, '/Deleting archived revisions.*1 revisions deleted/' ],