public function OAuth2ServerStorageTest::testSetRefreshToken in OAuth2 Server 8
Same name and namespace in other branches
- 2.0.x tests/src/Functional/OAuth2ServerStorageTest.php \Drupal\Tests\oauth2_server\Functional\OAuth2ServerStorageTest::testSetRefreshToken()
Set refresh token.
File
- tests/
src/ Functional/ OAuth2ServerStorageTest.php, line 187
Class
- OAuth2ServerStorageTest
- The OAuth2 Server admin test case.
Namespace
Drupal\Tests\oauth2_server\FunctionalCode
public function testSetRefreshToken() {
$user = $this
->drupalCreateUser([
'use oauth2 server',
]);
$token = (bool) $this->storage
->getRefreshToken('refreshtoken');
$this
->assertFalse($token, 'Trying to load a nonexistent token is unsuccessful.');
$expires = time() + 20;
$success = (bool) $this->storage
->setRefreshToken('refreshtoken', $this->clientId, $user
->id(), $expires);
$this
->assertTrue($success, 'A new refresh token has been successfully created.');
// Verify the return format of getRefreshToken().
$token = $this->storage
->getRefreshToken('refreshtoken');
$this
->assertTrue((bool) $token, 'A refresh token was successfully returned.');
$this
->assertArrayHasKey('refresh_token', $token, 'The "refresh_token" value is present in the token array.');
$this
->assertArrayHasKey('client_id', $token, 'The "client_id" value is present in the token array.');
$this
->assertArrayHasKey('user_id', $token, 'The "user_id" value is present in the token array.');
$this
->assertArrayHasKey('expires', $token, 'The "expires" value is present in the token array.');
$this
->assertEqual($token['refresh_token'], 'refreshtoken', 'The "refresh_token" key has the expected value.');
$this
->assertEqual($token['client_id'], $this->clientId, 'The "client_id" key has the expected value.');
$this
->assertEqual($token['user_id'], $user
->id(), 'The "user_id" key has the expected value.');
$this
->assertEqual($token['expires'], $expires, 'The "expires" key has the expected value.');
}