You are here

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

Test that cached pages can be served through the test front controller.

File

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

Class

AuthcacheBuiltinTestCacheBackend
Tests update functionality unrelated to the database.

Code

public function testDeliverThroughBackend() {
  $this
    ->drupalGet('node');
  $this
    ->assertResponse(200);
  $this
    ->assertFalse($this
    ->drupalGetHeader('X-Drupal-Cache'), t('X-Drupal-Cache header should be absent, when request was not delivered through authcache builtin backend.'));
  $this
    ->drupalGet($this->fcURL . '?q=node');
  $this
    ->assertResponse(200);
  $this
    ->assertFalse($this
    ->drupalGetHeader('X-Drupal-Cache'), t('X-Drupal-Cache header should be absent, when request was delivered through the test frontcontroller but without having specified that the backend should be used.'));
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x1));
  $this
    ->assertResponse(200);
  $this
    ->assertEqual('MISS', $this
    ->drupalGetHeader('X-Drupal-Cache'), t('X-Drupal-Cache header should be present, when request was delivered through authcache builtin backend.'));

  // Copy-paste from SimpleTestFunctionalTest::testUserAgentValidation.
  //
  // Generate a valid simpletest User-Agent to pass validation.
  $this
    ->assertTrue(preg_match('/simpletest\\d+/', $this->databasePrefix, $matches), 'Database prefix contains simpletest prefix.');
  $test_ua = drupal_generate_test_ua($matches[0]);

  // Now slightly modify the HMAC on the header, which should not validate.
  $this->additionalCurlOptions = array(
    CURLOPT_USERAGENT => $test_ua . 'X',
  );
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x1));
  $this
    ->assertResponse(403, 'Requesting test frontcontroller with a bad simpletest User-Agent fails.');

  // Use a real User-Agent and verify that the test frontcontroller can't be
  // accessed.
  $this->additionalCurlOptions = array(
    CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12',
  );
  $this
    ->drupalGet($this->fcURL . '?q=node', array(), $this
    ->buildRequestHeaders(0x1));
  $this
    ->assertResponse(403, 'Requesting test frontcontroller with a normal User-Agent fails.');
}