You are here

public function OauthTokenFileStorageTest::testSaveToken in Apigee Edge 8

Test that saving a token produces the expected file data.

File

tests/src/Kernel/OauthTokenFileStorageTest.php, line 149

Class

OauthTokenFileStorageTest
OAuth cache storage tests.

Namespace

Drupal\Tests\apigee_edge\Kernel

Code

public function testSaveToken() {
  $storage = $this
    ->tokenStorage();

  // Will use this to test expire.
  $current_time = time();

  // Save the token.
  $storage
    ->saveToken($this->testTokenData);

  // Load raw token data.
  $stored_token = unserialize(base64_decode(file_get_contents($this
    ->tokenFileUri())));

  // Test token values.
  $this
    ->assertSame($this->testTokenData['access_token'], $stored_token['access_token']);
  $this
    ->assertSame($this->testTokenData['token_type'], $stored_token['token_type']);
  $this
    ->assertSame($this->testTokenData['refresh_token'], $stored_token['refresh_token']);
  $this
    ->assertSame($this->testTokenData['scope'], $stored_token['scope']);

  // The difference in the timestamp should be 1 or 0 seconds.
  $this
    ->assertLessThan(2, abs($this->testTokenData['expires_in'] + $current_time - $stored_token['expires']));
}