You are here

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

Test cache-response with page_cache_maximum_age.

File

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

Class

AuthcacheBuiltinTestCacheBackend
Tests update functionality unrelated to the database.

Code

public function testCacheMaxAge() {
  $account = $this
    ->drupalCreateUser();
  variable_set('authcache_roles', array(
    DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
    DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
  ));

  // Test cache-control header for anonymous user.
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x3));
  $this
    ->assertResponse(200);
  $this
    ->assertEqual('MISS', $this
    ->drupalGetHeader('X-Drupal-Cache'), t('Cache miss on first request with anonymous user'));
  $this
    ->assertEqual('public, max-age=3600', $this
    ->drupalGetHeader('Cache-Control'), t('Cache-Control header set appropriately'));
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x3));
  $this
    ->assertResponse(200);
  $this
    ->assertEqual('HIT', $this
    ->drupalGetHeader('X-Drupal-Cache'), t('Cache hit on second request with anonymous user'));
  $this
    ->assertEqual('public, max-age=3600', $this
    ->drupalGetHeader('Cache-Control'), t('Cache-Control header set appropriately'));

  // Test cache-control header for authenticated user.
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x3));
  $this
    ->assertResponse(200);
  $this
    ->assertEqual('MISS', $this
    ->drupalGetHeader('X-Drupal-Cache'), t('Cache miss on first request with authenticated user'));
  $this
    ->assertEqual('public, max-age=3600', $this
    ->drupalGetHeader('Cache-Control'), t('Cache-Control header set appropriately'));
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x3));
  $this
    ->assertResponse(200);
  $this
    ->assertEqual('HIT', $this
    ->drupalGetHeader('X-Drupal-Cache'), t('Cache hit on first request with authenticated user'));
  $this
    ->assertEqual('public, max-age=3600', $this
    ->drupalGetHeader('Cache-Control'), t('Cache-Control header set appropriately'));
  $this
    ->drupalLogout();
}