ape.test in Advanced Page Expiration 7
Test integration for the advanced page expiration module.
File
ape.testView source
<?php
/**
* @file
* Test integration for the advanced page expiration module.
*/
/**
* Helper test class with some added functions for testing.
*/
class ApeTestHelper extends DrupalWebTestCase {
/**
* Register advanced page expiration tests with system.
*/
public static function getInfo() {
return array(
'name' => 'Advanced page expiration tests',
'description' => 'Test cache-control header is set correctly after configuration.',
'group' => 'Advanced page expiration',
);
}
/**
* Perform setup before testing.
*
* @param array $modules
* List of modules required for testing.
*/
public function setUp($modules = array()) {
$modules[] = 'ape';
$modules[] = 'path';
$modules[] = 'user';
$modules[] = 'common_test';
$modules[] = 'ape_test';
parent::setUp($modules);
variable_set('clean_url', 1);
variable_set('cache', 1);
variable_set('page_cache_maximum_age', 2592000);
variable_set('ape_alternatives', '<front>');
variable_set('ape_alternative_lifetime', 60);
variable_set('ape_exclusions', 'user/login');
variable_set('ape_301_lifetime', 1800);
variable_set('ape_302_lifetime', 600);
variable_set('ape_404_lifetime', 3600);
}
/**
* Test cache-control headers after configuration of the module.
*/
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.');
}
}
Classes
Name | Description |
---|---|
ApeTestHelper | Helper test class with some added functions for testing. |