public function AuthcacheBackendKeyManagementTestCase::testNoKeyRenewWhenKeyDoesNotChange in Authenticated User Page Caching (Authcache) 7.2
Do not call hook_authcache_backend_key_set when key remains the same.
File
- tests/
authcache.backend.test, line 356 - Test cases for pluggable cache backends.
Class
- AuthcacheBackendKeyManagementTestCase
- Test key management.
Code
public function testNoKeyRenewWhenKeyDoesNotChange() {
// Ensure that authcache will not attempt to renew the key if the correct
// one is supplied by the backend.
$backend_boot = $this->stubbackend
->hook('boot', array(
'authcache_backend_test',
'Cookie',
authcache_backend_anonymous_key(),
));
$key_set = $this->stubbackend
->hook('authcache_backend_key_set');
$this
->drupalGet('node');
$this
->assertStub($backend_boot, HookStub::once());
$this
->assertStub($key_set, HookStub::never());
// Repeat the test for an anonymous user with an open session.
$count = $this
->drupalGet('authcache-test-session-counter');
$this
->assertEqual(1, $count);
$count = $this
->drupalGet('authcache-test-session-counter');
$this
->assertEqual(2, $count);
$backend_boot = $this->stubbackend
->hook('boot', array(
'authcache_backend_test',
'Cookie',
authcache_backend_anonymous_key(),
));
$key_set = $this->stubbackend
->hook('authcache_backend_key_set');
$this
->drupalGet('node');
$this
->assertStub($backend_boot, HookStub::once());
$this
->assertStub($key_set, HookStub::never());
$count = $this
->drupalGet('authcache-test-session-counter');
$this
->assertEqual(3, $count);
$this
->drupalGet('authcache-test-session-clear');
// Repeat again for an authenticated user.
$this
->drupalLogin($this->member);
$user_key = $this
->drupalGetHeader('X-Authcache-Backend-Test-Key-Exit');
$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');
$backend_boot = $this->stubbackend
->hook('boot', array(
'authcache_backend_test',
'Cookie',
$user_key,
));
$key_set = $this->stubbackend
->hook('authcache_backend_key_set');
$this
->drupalGet('node');
$this
->assertStub($backend_boot, HookStub::once());
$this
->assertStub($key_set, HookStub::never());
$this
->drupalLogout();
}