3 namespace Drupal\Tests\system\Functional\System;
5 use Drupal\rest\Entity\RestResourceConfig;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests to see if generator header is added.
13 class ResponseGeneratorTest extends BrowserTestBase {
20 public static $modules = ['hal', 'rest', 'node', 'basic_auth'];
25 protected function setUp() {
27 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
29 $account = $this->drupalCreateUser(['access content']);
30 $this->drupalLogin($account);
34 * Test to see if generator header is added.
36 public function testGeneratorHeaderAdded() {
38 $node = $this->drupalCreateNode();
40 list($version) = explode('.', \Drupal::VERSION, 2);
41 $expectedGeneratorHeader = 'Drupal ' . $version . ' (https://www.drupal.org)';
43 // Check to see if the header is added when viewing a normal content page
44 $this->drupalGet($node->urlInfo());
45 $this->assertResponse(200);
46 $this->assertEqual('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
47 $this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator'));
49 // Check to see if the header is also added for a non-successful response
50 $this->drupalGet('llama');
51 $this->assertResponse(404);
52 $this->assertEqual('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
53 $this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator'));
55 // Enable cookie-based authentication for the entity:node REST resource.
56 /** @var \Drupal\rest\RestResourceConfigInterface $resource_config */
57 $resource_config = RestResourceConfig::load('entity.node');
58 $configuration = $resource_config->get('configuration');
59 $configuration['authentication'][] = 'cookie';
60 $resource_config->set('configuration', $configuration)->save();
63 // Tests to see if this also works for a non-html request
64 $this->drupalGet($node->toUrl()->setOption('query', ['_format' => 'hal_json']));
65 $this->assertResponse(200);
66 $this->assertEqual('application/hal+json', $this->drupalGetHeader('Content-Type'));
67 $this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator'));