You are here

public function HttpResponseHeadersTestCase::testHeaderRuleVisibility in HTTP Response Headers 7

Test header rule visibility.

File

./http_response_headers.test, line 46
Tests for http_response_headers.module.

Class

HttpResponseHeadersTestCase
@file Tests for http_response_headers.module.

Code

public function testHeaderRuleVisibility() {

  // Create a random name for the header rule.
  $name = $this
    ->randomName(8);
  $visibility_options = array();
  $visibility_options['pages'] = 'user*';
  $visibility_options['visibility'] = HTTP_RESPONSE_HEADERS_VISIBILITY_NOTLISTED;
  $visibility_options['roles'] = DRUPAL_AUTHENTICATED_RID;
  $header = 'Cache-Control';
  $header_value = 'max-age=3600';
  $this
    ->createHeaderRule(strtolower($name), $name, $header, $header_value, $visibility_options);
  $this
    ->drupalGet('');
  $headers = $this
    ->drupalGetHeaders();
  $this
    ->assertEqual($headers[strtolower($header)], $header_value, 'Header rule was applied on the front page.');
  $this
    ->drupalGet('user');
  $headers = $this
    ->drupalGetHeaders();
  $this
    ->assertNotEqual($headers[strtolower($header)], $header_value, 'Header rule was not applied according to block visibility rules.');
  $this
    ->drupalGet('USER/' . $this->adminUser->uid);
  $headers = $this
    ->drupalGetHeaders();
  $this
    ->assertNotEqual($headers[strtolower($header)], $header_value, 'Header rule was not applied according to header rule visibility rules regardless of path case.');

  // Confirm that the rule is not applied to anonymous users.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('');
  $headers = $this
    ->drupalGetHeaders();
  $this
    ->assertNotEqual($headers[strtolower($header)], $header_value, 'Header rule was not applied to anonymous users.');
}