public function AuthcacheBuiltinTestCacheBackend::testCacheRoundtrip in Authenticated User Page Caching (Authcache) 7.2
Test simple cache roundtrip for anonymous and authenticated users.
File
- modules/
authcache_builtin/ tests/ authcache_builtin.cache-backend.test, line 131 - Test cases for the Authcache Bultin Cache Backend module.
Class
- AuthcacheBuiltinTestCacheBackend
- Tests update functionality unrelated to the database.
Code
public function testCacheRoundtrip() {
$account1 = $this
->drupalCreateUser();
$account2 = $this
->drupalCreateUser();
variable_set('authcache_roles', array(
DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID,
DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID,
));
// Warm up cache with anonymous user.
$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 anonymous 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 second request with anonymous user'));
// Login and warm up cache with account1.
$this
->drupalLogin($account1);
$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'));
$this
->drupalLogout();
// Ensure that anonymous user still get a cached copy.
$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 subsequent request with anonymous user'));
// Login and ensure that we get a cache-hit with account2
$this
->drupalLogin($account2);
$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 other authenticated user'));
$this
->drupalLogout();
}