You are here

public function ApeTestHelper::testApeHeaders in Advanced Page Expiration 7

Test cache-control headers after configuration of the module.

File

./ape.test, line 51
Test integration for the advanced page expiration module.

Class

ApeTestHelper
Helper test class with some added functions for testing.

Code

public function testApeHeaders() {

  // Check user registration page has global age.
  $this
    ->drupalGet('user/register');
  $this
    ->assertEqual($this
    ->drupalGetHeader('Cache-Control'), 'public, max-age=2592000', 'Global Cache-Control header set.');

  // Check homepage has alternative age.
  $this
    ->drupalGet('');
  $this
    ->assertEqual($this
    ->drupalGetHeader('Cache-Control'), 'public, max-age=60', 'Alternative Cache-Control header set.');

  // Check login page is excluded from caching.
  $this
    ->drupalGet('user/login');
  $this
    ->assertEqual($this
    ->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Page successfully excluded from caching.');

  // Check that authenticated users bypass the cache.
  $user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('user');
  $this
    ->assertFalse($this
    ->drupalGetHeader('X-Drupal-Cache'), 'Caching was bypassed.');
  $this
    ->assertEqual($this
    ->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Cache-Control header was sent.');
  $this
    ->drupalLogout();

  // Check that 403 responses have configured age.
  $this
    ->drupalGet('admin/structure');
  $headers = $this
    ->drupalGetHeaders(TRUE);
  $this
    ->assertEqual($headers[0]['cache-control'], 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Forbidden page was not cached.');

  // Check that 404 responses have configured age.
  $this
    ->drupalGet('notfindingthat');
  $headers = $this
    ->drupalGetHeaders(TRUE);
  $this
    ->assertEqual($headers[0]['cache-control'], 'public, max-age=3600', '404 Page Not Found Cache-Control header set.');

  // Check that 301 redirects work correctly.
  $this
    ->drupalGet('ape_redirect_301');
  $headers = $this
    ->drupalGetHeaders(TRUE);
  $this
    ->assertEqual($headers[0]['cache-control'], 'public, max-age=1800', '301 redirect Cache-Control header set.');

  // Check that 302 redirects work correctly.
  $this
    ->drupalGet('ape_redirect_302');
  $headers = $this
    ->drupalGetHeaders(TRUE);
  $this
    ->assertEqual($headers[0]['cache-control'], 'public, max-age=600', '302 redirect Cache-Control header set.');
}