X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FSystem%2FResponseGeneratorTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FSystem%2FResponseGeneratorTest.php;h=592364636d954f36159d458f12ae45ace40de25c;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/system/tests/src/Functional/System/ResponseGeneratorTest.php b/web/core/modules/system/tests/src/Functional/System/ResponseGeneratorTest.php new file mode 100644 index 000000000..592364636 --- /dev/null +++ b/web/core/modules/system/tests/src/Functional/System/ResponseGeneratorTest.php @@ -0,0 +1,71 @@ +drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); + + $account = $this->drupalCreateUser(['access content']); + $this->drupalLogin($account); + } + + /** + * Test to see if generator header is added. + */ + public 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 cookie-based authentication for the entity:node REST resource. + /** @var \Drupal\rest\RestResourceConfigInterface $resource_config */ + $resource_config = RestResourceConfig::load('entity.node'); + $configuration = $resource_config->get('configuration'); + $configuration['authentication'][] = 'cookie'; + $resource_config->set('configuration', $configuration)->save(); + $this->rebuildAll(); + + // Tests to see if this also works for a non-html request + $this->drupalGet($node->toUrl()->setOption('query', ['_format' => 'hal_json'])); + $this->assertResponse(200); + $this->assertEqual('application/hal+json', $this->drupalGetHeader('Content-Type')); + $this->assertEqual($expectedGeneratorHeader, $this->drupalGetHeader('X-Generator')); + + } + +}