You are here

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

Test behavior when frontcontroller is not in the whitelist.

Basic rule 4: Do not cache when request did not came in via a whitelisted frontcontroller. Test with an empty list (removing the default entry pointing at index.php).

File

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

Class

AuthcacheBuiltinTestCacheBackend
Tests update functionality unrelated to the database.

Code

public function testDisableWhenFrontControllerNotInWhitelist() {
  $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'));

  // Empty list of allowed frontcontrollers.
  variable_set('authcache_frontcontroller_whitelist', array());
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x1));
  $this
    ->assertResponse(200);
  $this
    ->assertFalse($this
    ->drupalGetHeader('X-Drupal-Cache'), t('Do not attempt to serve page from cache when core page cache is active'));

  // Reset list of allowed frontcontrollers to default.
  variable_del('authcache_frontcontroller_whitelist');

  // Retry.
  $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 after core cache is disabled again'));
}