Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / PurgeRecentChangesTest.php
blob2c6a5eb0d88c17d18584acb17f8260cc2392f8c2
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use MediaWiki\MainConfigNames;
6 use PurgeRecentChanges;
7 use Wikimedia\Timestamp\ConvertibleTimestamp;
9 /**
10 * @covers \PurgeRecentChanges
11 * @group Database
12 * @author Dreamy Jazz
14 class PurgeRecentChangesTest extends MaintenanceBaseTestCase {
16 protected function getMaintenanceClass() {
17 return PurgeRecentChanges::class;
20 public function addDBData() {
21 // Make two testing edits, which will trigger a recentchanges insert. One of the edits will be made
22 // over wgRCMaxAge seconds ago while the other will be made a day ago
23 $testPage = $this->getExistingTestPage();
24 $testUser = $this->getTestUser()->getAuthority();
25 // So that only our two testing edits are present, and nothing from creating the test page or test user
26 $this->truncateTable( 'recentchanges' );
27 // Fix wgRCMaxAge at a high value to ensure that the recentchanges entries we are creating are not purged
28 // by later testing edits.
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 // Verify that the recentchanges table row count is as expected for the test
35 $this->newSelectQueryBuilder()
36 ->field( 'COUNT(*)' )
37 ->table( 'recentchanges' )
38 ->assertFieldValue( 2 );
41 public function testExecute() {
42 // Set the time as one day beyond the last testing edit made in ::addDBData
43 ConvertibleTimestamp::setFakeTime( '20240406060708' );
44 // Fix wgRCMaxAge for the test, in case the default value changes.
45 $this->overrideConfigValue( MainConfigNames::RCMaxAge, 90 * 24 * 3600 );
46 // Run the maintenance script
47 $this->maintenance->execute();
48 // Verify that only the edit made a day ago is now in the recentchanges table
49 $this->newSelectQueryBuilder()
50 ->field( 'rc_timestamp' )
51 ->table( 'recentchanges' )
52 ->assertFieldValue( $this->getDb()->timestamp( '20240405060708' ) );