ResponseGeneratorTest.php in Drupal 8
File
core/modules/system/tests/src/Functional/System/ResponseGeneratorTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\System;
use Drupal\rest\Entity\RestResourceConfig;
use Drupal\Tests\BrowserTestBase;
class ResponseGeneratorTest extends BrowserTestBase {
public static $modules = [
'hal',
'rest',
'node',
'basic_auth',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
$account = $this
->drupalCreateUser([
'access content',
]);
$this
->drupalLogin($account);
}
public function testGeneratorHeaderAdded() {
$node = $this
->drupalCreateNode();
list($version) = explode('.', \Drupal::VERSION, 2);
$expectedGeneratorHeader = 'Drupal ' . $version . ' (https://www.drupal.org)';
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertEqual('text/html; charset=UTF-8', $this
->drupalGetHeader('Content-Type'));
$this
->assertEqual($expectedGeneratorHeader, $this
->drupalGetHeader('X-Generator'));
$this
->drupalGet('llama');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertEqual('text/html; charset=UTF-8', $this
->drupalGetHeader('Content-Type'));
$this
->assertEqual($expectedGeneratorHeader, $this
->drupalGetHeader('X-Generator'));
$resource_config = RestResourceConfig::load('entity.node');
$configuration = $resource_config
->get('configuration');
$configuration['authentication'][] = 'cookie';
$resource_config
->set('configuration', $configuration)
->save();
$this
->rebuildAll();
$this
->drupalGet($node
->toUrl()
->setOption('query', [
'_format' => 'hal_json',
]));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertEqual('application/hal+json', $this
->drupalGetHeader('Content-Type'));
$this
->assertEqual($expectedGeneratorHeader, $this
->drupalGetHeader('X-Generator'));
}
}