ResponseGeneratorTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/System/ResponseGeneratorTest.php
View source
<?php
namespace Drupal\system\Tests\System;
use Drupal\rest\Tests\RESTTestBase;
class ResponseGeneratorTest extends RESTTestBase {
public static $modules = array(
'hal',
'rest',
'node',
);
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType(array(
'type' => 'page',
'name' => 'Basic page',
));
$permissions = $this
->entityPermissions('node', 'view');
$permissions[] = 'restful get entity:node';
$account = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($account);
}
function testGeneratorHeaderAdded() {
$node = $this
->drupalCreateNode();
list($version) = explode('.', \Drupal::VERSION, 2);
$expectedGeneratorHeader = 'Drupal ' . $version . ' (https://www.drupal.org)';
$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'));
$this
->drupalGet('llama');
$this
->assertResponse(404);
$this
->assertEqual('text/html; charset=UTF-8', $this
->drupalGetHeader('Content-Type'));
$this
->assertEqual($expectedGeneratorHeader, $this
->drupalGetHeader('X-Generator'));
$this
->enableService('entity:node', 'GET', 'json');
$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'));
}
}