wiki.techinc.nl/tests/phpunit/includes/api/query/ApiQueryTokensTest.php
Daimona Eaytoy 2a0de02aab phpunit: Avoid TestUser in non-database tests
TestUser creates the user and therefore needs the database. Avoid using
it in non-database tests.

Add ApiQueryBlockInfoTraitTest to the Database group because it needs
the database.

Add DeleteUserEmailTest to the Database group because since 3bedffa8
the default user is not created any more in non-database tests

Change-Id: Iff438964dde47a47a2fa4a314d55010bd8c7fee5
2023-07-29 14:26:50 +00:00

63 lines
1.8 KiB
PHP

<?php
use MediaWiki\MainConfigNames;
/**
* @group API
* @group medium
* @covers ApiQueryTokens
*/
class ApiQueryTokensTest extends ApiTestCase {
public function testGetCsrfToken() {
$params = [
'action' => 'query',
'meta' => 'tokens',
'type' => 'csrf',
];
$apiResult = $this->doApiRequest( $params );
$this->assertArrayHasKey( 'query', $apiResult[0] );
$this->assertArrayHasKey( 'tokens', $apiResult[0]['query'] );
$this->assertArrayHasKey( 'csrftoken', $apiResult[0]['query']['tokens'] );
$this->assertStringEndsWith( '+\\', $apiResult[0]['query']['tokens']['csrftoken'] );
}
public function testGetAllTokens() {
$params = [
'action' => 'query',
'meta' => 'tokens',
'type' => '*',
];
$apiResult = $this->doApiRequest( $params );
$this->assertArrayHasKey( 'query', $apiResult[0] );
$this->assertArrayHasKey( 'tokens', $apiResult[0]['query'] );
// MW core has 7 token types (createaccount, csrf, login, patrol, rollback, userrights, watch)
$this->assertGreaterThanOrEqual( 7, count( $apiResult[0]['query']['tokens'] ) );
}
public function testContinuation(): void {
// one token is 42 characters, so 100 is enough for 2 tokens but not 3
$size = 100;
$this->overrideConfigValue( MainConfigNames::APIMaxResultSize, $size );
[ $result ] = $this->doApiRequest( [
'action' => 'query',
'meta' => 'tokens',
'type' => 'csrf|patrol|watch',
] );
$this->assertSame(
wfMessage( 'apiwarn-truncatedresult', Message::numParam( $size ) )
->text(),
$result['warnings']['result']['warnings']
);
$this->assertSame( [ 'csrftoken', 'patroltoken' ], array_keys( $result['query']['tokens'] ) );
$this->assertTrue( $result['batchcomplete'], 'batchcomplete should be true' );
$this->assertSame( [ 'type' => 'watch', 'continue' => '-||' ], $result['continue'] );
}
}