diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index ca119ffc81f..5d3a2ff16e7 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -46,6 +46,7 @@ use Wikimedia\Rdbms\IExpression; use Wikimedia\Rdbms\IReadableDatabase; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\RawSQLValue; +use Wikimedia\Timestamp\ConvertibleTimestamp; /** * Special page which uses a ChangesList to show query results. @@ -1521,7 +1522,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { } // Calculate cutoff - $cutoff_unixtime = time() - $opts['days'] * 3600 * 24; + $cutoff_unixtime = ConvertibleTimestamp::time() - $opts['days'] * 3600 * 24; $cutoff = $dbr->timestamp( $cutoff_unixtime ); $fromValid = preg_match( '/^[0-9]{14}$/', $opts['from'] ); @@ -1823,7 +1824,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { 'experienced' => $config->get( MainConfigNames::ExperiencedUserMemberSince ), ][$level]; if ( $now === 0 ) { - $now = time(); + $now = ConvertibleTimestamp::time(); } $secondsPerDay = 86400; $timeCutoff = $now - $configSince * $secondsPerDay; diff --git a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php index 2f976cd7fd2..be110ae76d4 100644 --- a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php +++ b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php @@ -14,6 +14,7 @@ use MediaWiki\User\User; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IExpression; use Wikimedia\TestingAccessWrapper; +use Wikimedia\Timestamp\ConvertibleTimestamp; /** * Test class for ChangesListSpecialPage class @@ -681,36 +682,46 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase public function testFilterUserExpLevelUnregisteredOrExperienced() { $this->disableAutoCreateTempUser(); - [ $cond ] = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] ); - $this->assertMatchesRegularExpression( - '/\(actor_user IS NULL OR ' - . '\(actor_user IS NOT NULL AND \(' - . 'user_editcount >= 500 AND \(user_registration IS NULL OR ' - . 'user_registration <= \'[^\']+\'\)' - . '\)\)\)/', - $cond->toSql( $this->getDb() ), + ConvertibleTimestamp::setFakeTime( '20201231000000' ); + $this->assertConditions( + [ + # expected + "(actor_user IS NULL OR " + . "(actor_user IS NOT NULL AND (" + . "user_editcount >= 500 AND (user_registration IS NULL OR " + . "user_registration <= '{$this->getDb()->timestamp( '20201201000000' )}')" + . ")))" + ], + [ + 'userExpLevel' => 'unregistered;experienced' + ], "rc conditions: userExpLevel=unregistered;experienced" ); } public function testFilterUserExpLevelUnregisteredOrExperiencedWhenTemporaryAccountsEnabled() { $this->enableAutoCreateTempUser(); - [ $cond ] = $this->buildQuery( [ 'userExpLevel' => 'unregistered;experienced' ] ); + ConvertibleTimestamp::setFakeTime( '20201231000000' ); + $notLikeTempUserMatchExpression = $this->getServiceContainer()->getTempUserConfig() ->getMatchCondition( $this->getDb(), 'actor_name', IExpression::NOT_LIKE ) ->toSql( $this->getDb() ); - $notLikeTempUserMatchExpression = preg_quote( $notLikeTempUserMatchExpression ); $likeTempUserMatchExpression = $this->getServiceContainer()->getTempUserConfig() ->getMatchCondition( $this->getDb(), 'actor_name', IExpression::LIKE ) ->toSql( $this->getDb() ); - $likeTempUserMatchExpression = preg_quote( $likeTempUserMatchExpression ); - $this->assertMatchesRegularExpression( - "/\(\(actor_user IS NULL OR $likeTempUserMatchExpression\) OR " - . "\(\(actor_user IS NOT NULL AND $notLikeTempUserMatchExpression\) AND \(" - . 'user_editcount >= 500 AND \(user_registration IS NULL OR ' - . 'user_registration <= \'[^\']+\'\)' - . '\)\)\)/', - $cond->toSql( $this->getDb() ), + + $this->assertConditions( + [ + # expected + "((actor_user IS NULL OR $likeTempUserMatchExpression) OR " + . "((actor_user IS NOT NULL AND $notLikeTempUserMatchExpression) AND (" + . "user_editcount >= 500 AND (user_registration IS NULL OR " + . "user_registration <= '{$this->getDb()->timestamp( '20201201000000' )}')" + . ")))" + ], + [ + 'userExpLevel' => 'unregistered;experienced' + ], "rc conditions: userExpLevel=unregistered;experienced" ); }