You are here

public function OauthTokenFileStorageTest::testStaticCaching in Apigee Edge 8

Test the token storage is using static cache.

File

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

Class

OauthTokenFileStorageTest
OAuth cache storage tests.

Namespace

Drupal\Tests\apigee_edge\Kernel

Code

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

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

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

  // Create a new access token and write it to file.
  $stored_token['access_token'] = mb_strtolower($this
    ->randomMachineName(32));
  \Drupal::service('file_system')
    ->saveData(base64_encode(serialize($stored_token)), $this
    ->tokenFileUri(), FileSystemInterface::EXISTS_REPLACE);

  // Make sure the cached version is still returned.
  $this
    ->assertSame($access_token, $storage
    ->getAccessToken());
}