You are here

public function HttpResponseHeadersUITestCase::testHeaderRuleVisibility in HTTP Response Headers 7

Test header rule visibility.

File

modules/http_response_headers_ui/http_response_headers_ui.test, line 97
Tests for http_response_headers_ui.module.

Class

HttpResponseHeadersUITestCase
@file Tests for http_response_headers_ui.module.

Code

public function testHeaderRuleVisibility() {

  // Create a random name for the header rule.
  $name = $this
    ->randomName(8);
  $visibility_options = array();
  $header = 'Cache-Control';
  $header_value = 'max-age=3600';
  $this
    ->createHeaderRule(strtolower($name), $name, $header, $header_value, $visibility_options);
  $machine_name = db_query("SELECT machine_name FROM {http_response_headers} WHERE description= :name", array(
    ':name' => strtolower($name),
  ))
    ->fetchField();

  // Set the header rule to be not applied on any user path, and to be
  // applied only to authenticated users.
  $edit = array();
  $edit['pages'] = 'user*';
  $edit['visibility'] = HTTP_RESPONSE_HEADERS_VISIBILITY_NOTLISTED;
  $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
  $this
    ->drupalPost('admin/config/system/http-response-headers/list/' . $machine_name . '/edit', $edit, t('Save'));
  $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.');
}