wiki.techinc.nl/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php
Umherirrender 8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00

57 lines
1.8 KiB
PHP

<?php
/**
* @group API
* @group Database
* @group medium
* @covers ApiQueryUserInfo
*/
class ApiQueryUserInfoTest extends ApiTestCase {
/**
* @throws MWContentSerializationException
* @throws MWException
* @covers ApiQueryUserInfo::getLatestContributionTime
*/
public function testTimestamp() {
$clock = MWTimestamp::convert( TS_UNIX, '20100101000000' );
MWTimestamp::setFakeTime( static function () use ( &$clock ) {
return $clock += 1000;
} );
$params = [
'action' => 'query',
'meta' => 'userinfo',
'uiprop' => 'latestcontrib',
];
$page = $this->getNonexistingTestPage();
$user = $this->getTestUser()->getUser();
$apiResult = $this->doApiRequest( $params, null, false, $user );
$this->assertArrayNotHasKey( 'continue', $apiResult[0] );
$this->assertArrayHasKey( 'query', $apiResult[0] );
$this->assertArrayHasKey( 'userinfo', $apiResult[0]['query'] );
$this->assertArrayNotHasKey( 'latestcontrib', $apiResult[0]['query']['userinfo'] );
$status = $this->editPage( $page, 'one' );
$this->assertTrue( $status->isOK() );
$status = $this->editPage( $page, 'two' );
$this->assertTrue( $status->isOK() );
$revisionTimestamp = MWTimestamp::convert( TS_ISO_8601, $page->getTimestamp() );
$apiResult = $this->doApiRequest( $params, null, false, $user );
$this->assertArrayNotHasKey( 'continue', $apiResult[0] );
$this->assertArrayHasKey( 'query', $apiResult[0] );
$this->assertArrayHasKey( 'userinfo', $apiResult[0]['query'] );
$this->assertArrayHasKey( 'latestcontrib', $apiResult[0]['query']['userinfo'] );
$queryTimestamp = $apiResult[0]['query']['userinfo']['latestcontrib'];
$this->assertSame( $revisionTimestamp, $queryTimestamp );
}
public function tearDown(): void {
parent::tearDown();
MWTimestamp::setFakeTime( false );
}
}