public function HttpResponseHeadersTestCase::testHeaderRuleHelpers in HTTP Response Headers 7
Test header rule helpers that changes the user input.
File
- ./
http_response_headers.test, line 106 - Tests for http_response_headers.module.
Class
- HttpResponseHeadersTestCase
- @file Tests for http_response_headers.module.
Code
public function testHeaderRuleHelpers() {
// Create a header rule with 'Expires' header.
$name = $this
->randomName(8);
$visibility_options = array(
'pages' => 'user*',
'visibility' => HTTP_RESPONSE_HEADERS_VISIBILITY_LISTED,
);
$header = 'Expires';
$header_value = '3600';
$this
->createHeaderRule(strtolower($name), $name, $header, $header_value, $visibility_options);
// Get user page to check Expires has
// 'Mon, 14 Oct 2013 15:42:25 +0000' format value, instead of 3600.
$this
->drupalGet('user');
$expected_value = http_response_headers_expires_callback($header_value);
$headers = $this
->drupalGetHeaders();
$this
->assertEqual($headers[strtolower($header)], $expected_value, 'Expires header was applied to user pages.');
// Create a header rule with 'Last-Modified' header.
$name = $this
->randomName(8);
$visibility_options = array(
'pages' => 'user*',
'visibility' => HTTP_RESPONSE_HEADERS_VISIBILITY_LISTED,
);
$header = 'Last-Modified';
$header_value = '3600';
$this
->createHeaderRule(strtolower($name), $name, $header, $header_value, $visibility_options);
// Get user page to check Last-Modified has
// 'Mon, 14 Oct 2013 15:42:25 GMT' format value, instead of 3600.
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified
$this
->drupalGet('user');
$headers = $this
->drupalGetHeaders();
$rfc7231 = preg_match('/[A-Z][a-z]{2}, [0-9]{1,2} [A-Z][a-z]{2} [0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} GMT/', $headers[strtolower($header)]);
$this
->assertTrue((bool) $rfc7231, 'Last-Modified header matching DATE_RFC7231 was applied to user pages.');
// Check the Last-Modified header matched the Date header. This is somewhat
// reliant on the webserver, but most seem to follow the spec.
// @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date
// N.B. this test is only valid for an uncached response.
// @see http_response_headers_last_modified_callback()
$this
->assertEqual($headers[strtolower($header)], $headers[strtolower('Date')], 'Last-Modified header matched the Date response header.');
}