You are here

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

Ensure that responses to POST request will not be served from cache.

File

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

Class

AuthcacheBuiltinTestCacheBackend
Tests update functionality unrelated to the database.

Code

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

  // We need to post manually here, drupalPost would attempt to GET the form
  // before (and would fail).
  $this
    ->curlExec(array(
    CURLOPT_URL => $this->fcURL . '?q=node',
    CURLOPT_POST => TRUE,
    CURLOPT_POSTFIELDS => '',
    CURLOPT_HTTPHEADER => $this
      ->buildRequestHeaders(0x1),
  ));

  // Ensure that any changes to variables in the other thread are picked up.
  $this
    ->refreshVariables();
  $this
    ->assertResponse(200);
  $this
    ->assertFalse($this
    ->drupalGetHeader('X-Drupal-Cache'), t('Cache miss on first request after key cache was cleared'));
}