diff --git a/core/modules/system/src/Tests/System/ResponseGeneratorTest.php b/core/modules/system/src/Tests/System/ResponseGeneratorTest.php new file mode 100644 index 0000000..061f7f9 --- /dev/null +++ b/core/modules/system/src/Tests/System/ResponseGeneratorTest.php @@ -0,0 +1,72 @@ +drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + + $permissions = $this->entityPermissions('node', 'view'); + $permissions[] = 'restful get entity:node'; + $account = $this->drupalCreateUser($permissions); + $this->drupalLogin($account); + } + + /** + * Test to see if generator header is added. + */ + 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(), 'GET', NULL, 'application/json'); + $this->assertResponse(200); + $this->assertEqual('application/json', $this->drupalGetHeader('Content-Type')); + $this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator')); + + } + +}