public function HtmlResponseAttachmentsTest::testAttachments in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::testAttachments()
- 10 core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::testAttachments()
Tests 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
->assertEquals($expected_link_headers, $this
->getSession()
->getResponseHeaders()['Link']);
}