You are here

public function AuthcacheTestBackend::testVaryHeaderWithAuthcacheConfig in Authenticated User Page Caching (Authcache) 7.2

Test presence of X-Authcache-Key header on HTTP response.

File

tests/authcache.backend.test, line 112
Test cases for pluggable cache backends.

Class

AuthcacheTestBackend
Cover authcache module.

Code

public function testVaryHeaderWithAuthcacheConfig() {

  // Setup backend.
  $vary_header = $this
    ->randomName(8);
  $params = array(
    'authcache_backend_test',
    $vary_header,
  );

  // Test whether expected vary header is present for anonymous users.
  $hook_boot = $this->stubbackend
    ->hook('boot', $params);
  $hook_save = $this->stubbackend
    ->hook('authcache_backend_cache_save');
  $this
    ->drupalGet('<front>');
  $this
    ->assertVary($vary_header);
  $this
    ->assertCacheControl('max-age=3600');
  $this
    ->assertCacheControl('public');
  $this
    ->assertNoCacheControl('must-revalidate');
  $this
    ->assertNoCacheControl('no-cache');
  $this
    ->assertStub($hook_boot, HookStub::once());
  $this
    ->assertStub($hook_save, HookStub::once());

  // Test whether expected Vary header is present for authenticated users.
  $this
    ->drupalLogin($this->member);
  $hook_boot = $this->stubbackend
    ->hook('boot', $params);
  $hook_save = $this->stubbackend
    ->hook('authcache_backend_cache_save');
  $this
    ->drupalGet('<front>');
  $this
    ->assertVary($vary_header);
  $this
    ->assertCacheControl('max-age=3600');
  $this
    ->assertCacheControl('public');
  $this
    ->assertNoCacheControl('must-revalidate');
  $this
    ->assertNoCacheControl('no-cache');
  $this
    ->assertStub($hook_boot, HookStub::once());
  $this
    ->assertStub($hook_save, HookStub::once());
}