| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\MainConfigNames; |
| 6 |
use PurgeRecentChanges; |
| 7 |
use Wikimedia\Timestamp\ConvertibleTimestamp; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class PurgeRecentChangesTest extends MaintenanceBaseTestCase { |
| 15 |
|
| 16 |
protected function getMaintenanceClass() { |
| 17 |
return PurgeRecentChanges::class; |
| 18 |
} |
| 19 |
|
| 20 |
public function addDBData() { |
| 21 |
|
| 22 |
|
| 23 |
$testPage = $this->getExistingTestPage(); |
| 24 |
$testUser = $this->getTestUser()->getAuthority(); |
| 25 |
|
| 26 |
$this->truncateTable( 'recentchanges' ); |
| 27 |
|
| 28 |
|
| 29 |
$this->overrideConfigValue( MainConfigNames::RCMaxAge, 24 * 3600 * 1000 ); |
| 30 |
ConvertibleTimestamp::setFakeTime( '20230405060708' ); |
| 31 |
$this->editPage( $testPage, 'testing1234', '', NS_MAIN, $testUser ); |
| 32 |
ConvertibleTimestamp::setFakeTime( '20240405060708' ); |
| 33 |
$this->editPage( $testPage, 'testing12345', '', NS_MAIN, $testUser ); |
| 34 |
|
| 35 |
$this->newSelectQueryBuilder() |
| 36 |
->field( 'COUNT(*)' ) |
| 37 |
->table( 'recentchanges' ) |
| 38 |
->assertFieldValue( 2 ); |
| 39 |
} |
| 40 |
|
| 41 |
public function testExecute() { |
| 42 |
|
| 43 |
ConvertibleTimestamp::setFakeTime( '20240406060708' ); |
| 44 |
|
| 45 |
$this->overrideConfigValue( MainConfigNames::RCMaxAge, 90 * 24 * 3600 ); |
| 46 |
|
| 47 |
$this->maintenance->execute(); |
| 48 |
|
| 49 |
$this->newSelectQueryBuilder() |
| 50 |
->field( 'rc_timestamp' ) |
| 51 |
->table( 'recentchanges' ) |
| 52 |
->assertFieldValue( $this->getDb()->timestamp( '20240405060708' ) ); |
| 53 |
} |
| 54 |
} |