public function HtmlResponseAttachmentsTest::testAttachments in Drupal 8
Same name and namespace in other branches
- 9 core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::testAttachments()
Test rendering of ['#attached'].
File
- core/
modules/ system/ tests/ src/ Functional/ Render/ HtmlResponseAttachmentsTest.php, line 29
Class
- HtmlResponseAttachmentsTest
- Functional tests for HtmlResponseAttachmentsProcessor.
Namespace
Drupal\Tests\system\Functional\RenderCode
public function testAttachments() {
// Test ['#attached']['http_header] = ['Status', $code].
$this
->drupalGet('/render_attached_test/teapot');
$this
->assertSession()
->statusCodeEquals(418);
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'MISS');
// Repeat for the cache.
$this
->drupalGet('/render_attached_test/teapot');
$this
->assertSession()
->statusCodeEquals(418);
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'HIT');
// Test ['#attached']['http_header'] with various replacement rules.
$this
->drupalGet('/render_attached_test/header');
$this
->assertTeapotHeaders();
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'MISS');
// Repeat for the cache.
$this
->drupalGet('/render_attached_test/header');
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'HIT');
// Test ['#attached']['feed'].
$this
->drupalGet('/render_attached_test/feed');
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this
->assertFeed();
// Repeat for the cache.
$this
->drupalGet('/render_attached_test/feed');
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'HIT');
// Test ['#attached']['html_head'].
$this
->drupalGet('/render_attached_test/head');
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'MISS');
$this
->assertHead();
// Repeat for the cache.
$this
->drupalGet('/render_attached_test/head');
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache', 'HIT');
// Test ['#attached']['html_head_link'] when outputted as HTTP header.
$this
->drupalGet('/render_attached_test/html_header_link');
$expected_link_headers = [
'</foo?bar=<baz>&baz=false>; rel="alternate"',
'</foo/bar>; hreflang="nl"; rel="alternate"',
];
$this
->assertEqual($this
->getSession()
->getResponseHeaders()['Link'], $expected_link_headers);
}