You are here

public function AuthcacheBuiltinTestCacheBackend::testKeyLoginLogout in Authenticated User Page Caching (Authcache) 7.2

Verify that the key cache is set with the proper values.

File

modules/authcache_builtin/tests/authcache_builtin.cache-backend.test, line 399
Test cases for the Authcache Bultin Cache Backend module.

Class

AuthcacheBuiltinTestCacheBackend
Tests update functionality unrelated to the database.

Code

public function testKeyLoginLogout() {
  global $base_root;
  variable_set('authcache_key_lifetime', 0);

  // Login and retrieve authcache key.
  $this
    ->drupalLogin($this->member);
  $key_cache_cid = $base_root . ':' . $this->session_id;
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x1));
  $user_key = $this
    ->drupalGetHeader('X-Authcache-Builtin-Test-Key');
  $this
    ->assertTrue($user_key, 'User key is not empty');
  $this
    ->assertNotEqual(authcache_backend_anonymous_key(), $user_key, 'User key is not same as the anonymous key');

  // Issue a normal page request and ensure that the key cache was populated.
  $now = time();
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x1));
  $cache = cache_get($key_cache_cid, 'cache_authcache_key');
  $this
    ->assertEqual($user_key, $cache->data);
  $this
    ->assertEqual(CACHE_TEMPORARY, $cache->expire);

  // Logout and ensure that the key is gone from the cache.
  $this
    ->drupalGet($this->fcURL . '?q=user/logout', array(), $this
    ->buildRequestHeaders(0x1));
  $cache = cache_get($key_cache_cid, 'cache_authcache_key');
  $this
    ->assertFalse($cache);
}