public function AuthcacheBuiltinTestCacheBackend::testCachePreclusion in Authenticated User Page Caching (Authcache) 7.2
Preclusion: Suppress subsequent page request being delivered from cache.
File
- modules/
authcache_builtin/ tests/ authcache_builtin.cache-backend.test, line 176 - Test cases for the Authcache Bultin Cache Backend module.
Class
- AuthcacheBuiltinTestCacheBackend
- Tests update functionality unrelated to the database.
Code
public function testCachePreclusion() {
$account = $this
->drupalCreateUser();
variable_set('authcache_roles', array(
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
));
// Login and warm up cache.
$this
->drupalLogin($account);
$this
->drupalGet($this->fcURL . '?q=node', array(), $this
->buildRequestHeaders(0x1));
$this
->assertResponse(200);
$this
->assertEqual('MISS', $this
->drupalGetHeader('X-Drupal-Cache'), t('Cache miss on first request with authenticated user'));
$this
->drupalGet($this->fcURL . '?q=node', array(), $this
->buildRequestHeaders(0x1));
$this
->assertResponse(200);
$this
->assertEqual('HIT', $this
->drupalGetHeader('X-Drupal-Cache'), t('Cache hit on first request with authenticated user'));
// Trigger preclusion. We have to ensure that we're not served a cached
// response, otherwise the stub will not be called.
$preclude_stub = $this->stubmod
->hook('authcache_preclude', t('Test'));
$this
->drupalGet($this->fcURL . '?q=user', array(), $this
->buildRequestHeaders(0x1));
$this
->assertResponse(200);
$this
->assertEqual('MISS', $this
->drupalGetHeader('X-Drupal-Cache'), t('User profile is not cached by default'));
$this
->assertStub($preclude_stub, HookStub::once());
HookStub::off('authcache_builtin_test_authcache_preclude');
// Ensure that next page request is not delivered from the cache.
$this
->drupalGet($this->fcURL . '?q=node', array(), $this
->buildRequestHeaders(0x1));
$this
->assertResponse(200);
$this
->assertFalse($this
->drupalGetHeader('X-Drupal-Cache'), t('Cache miss on first request following preclusion'));
// Ensure that the following page request is delivered from the cache.
$this
->drupalGet($this->fcURL . '?q=node', array(), $this
->buildRequestHeaders(0x1));
$this
->assertResponse(200);
$this
->assertEqual('HIT', $this
->drupalGetHeader('X-Drupal-Cache'), t('Cache hit on second request following preclusion'));
$this
->drupalLogout();
}