You are here

function ResponseGeneratorTest::testGeneratorHeaderAdded in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/System/ResponseGeneratorTest.php \Drupal\system\Tests\System\ResponseGeneratorTest::testGeneratorHeaderAdded()

Test to see if generator header is added.

File

core/modules/system/src/Tests/System/ResponseGeneratorTest.php, line 42
Contains \Drupal\system\Tests\System\ResponseGeneratorTest.

Class

ResponseGeneratorTest
Tests to see if generator header is added.

Namespace

Drupal\system\Tests\System

Code

function testGeneratorHeaderAdded() {
  $node = $this
    ->drupalCreateNode();
  list($version) = explode('.', \Drupal::VERSION, 2);
  $expectedGeneratorHeader = 'Drupal ' . $version . ' (https://www.drupal.org)';

  // Check to see if the header is added when viewing a normal content page
  $this
    ->drupalGet($node
    ->urlInfo());
  $this
    ->assertResponse(200);
  $this
    ->assertEqual('text/html; charset=UTF-8', $this
    ->drupalGetHeader('Content-Type'));
  $this
    ->assertEqual($expectedGeneratorHeader, $this
    ->drupalGetHeader('X-Generator'));

  // Check to see if the header is also added for a non-successful response
  $this
    ->drupalGet('llama');
  $this
    ->assertResponse(404);
  $this
    ->assertEqual('text/html; charset=UTF-8', $this
    ->drupalGetHeader('Content-Type'));
  $this
    ->assertEqual($expectedGeneratorHeader, $this
    ->drupalGetHeader('X-Generator'));

  // Enable rest API for nodes
  $this
    ->enableService('entity:node', 'GET', 'json');

  // Tests to see if this also works for a non-html request
  $this
    ->httpRequest($node
    ->urlInfo()
    ->setOption('query', [
    '_format' => 'json',
  ]), 'GET');
  $this
    ->assertResponse(200);
  $this
    ->assertEqual('application/json', $this
    ->drupalGetHeader('Content-Type'));
  $this
    ->assertEqual($expectedGeneratorHeader, $this
    ->drupalGetHeader('X-Generator'));
}