function HtmlResponseAttachmentsTest::testAttachments

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::testAttachments()
  2. 10 core/modules/system/tests/src/Functional/Render/HtmlResponseAttachmentsTest.php \Drupal\Tests\system\Functional\Render\HtmlResponseAttachmentsTest::testAttachments()
  3. 11.x 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\Render

Code

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=&lt;baz&gt;&amp;baz=false>; rel="alternate"',
    '</foo/bar>; hreflang="nl"; rel="alternate"',
  ];
  $this->assertEqual($this->getSession()
    ->getResponseHeaders()['Link'], $expected_link_headers);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.