You are here

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

Test value of Etag header.

File

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

Class

AuthcacheTestBackend
Cover authcache module.

Code

public function testEtagHeader() {

  // Test whether Etag header is added to cacheable responses for anonymous
  // users.
  $hook_boot = $this->stubbackend
    ->hook('boot');
  $hook_save = $this->stubbackend
    ->hook('authcache_backend_cache_save');
  $this
    ->drupalGet('<front>');
  $etag = $this
    ->drupalGetHeader('Etag');
  $this
    ->assertTrue($etag, 'Etag header on response when caching is enabled');
  $this
    ->assertTrue(preg_match('/^"[0-9]+-[01]"$/', $etag), 'Etag header matches regexp /^"[0-9]+-[01]"$/');
  $this
    ->assertStub($hook_boot, HookStub::once());
  $this
    ->assertStub($hook_save, HookStub::once());

  // Test whether Etag header is added to cacheable responses for
  // authenticated users.
  $this
    ->drupalLogin($this->member);
  $hook_boot = $this->stubbackend
    ->hook('boot');
  $hook_save = $this->stubbackend
    ->hook('authcache_backend_cache_save');
  $this
    ->drupalGet('<front>');
  $etag = $this
    ->drupalGetHeader('Etag');
  $this
    ->assertTrue($etag, 'Etag header on response when caching is enabled');
  $this
    ->assertTrue(preg_match('/^"[0-9]+-[01]-[0-9a-f]{7}"$/', $etag), 'Etag header matches regexp /^"[0-9]+-[01]-[0-9a-f]{7}"$/');
  $this
    ->assertStub($hook_boot, HookStub::once());
  $this
    ->assertStub($hook_save, HookStub::once());
}