You are here

public function OauthTokenFileStorageTest::testGetters in Apigee Edge 8

Test the get and has methods of the cache storage.

File

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

Class

OauthTokenFileStorageTest
OAuth cache storage tests.

Namespace

Drupal\Tests\apigee_edge\Kernel

Code

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

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

  // Save the token.
  $storage
    ->saveToken($this->testTokenData);
  $this
    ->assertSame($this->testTokenData['access_token'], $storage
    ->getAccessToken());
  $this
    ->assertSame($this->testTokenData['token_type'], $storage
    ->getTokenType());
  $this
    ->assertSame($this->testTokenData['refresh_token'], $storage
    ->getRefreshToken());
  $this
    ->assertSame($this->testTokenData['scope'], $storage
    ->getScope());

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

  // The token should still be valid for 5 minutes.
  $this
    ->assertFalse($storage
    ->hasExpired());

  // Expire token.
  $storage
    ->markExpired();

  // The token should not be valid anymore.
  $this
    ->assertTrue($storage
    ->hasExpired());
}