You are here

public function NodeViewTest::testLinkHeader in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeViewTest.php \Drupal\Tests\node\Functional\NodeViewTest::testLinkHeader()

Tests the Link header.

File

core/modules/node/tests/src/Functional/NodeViewTest.php, line 38

Class

NodeViewTest
Tests the node/{node} page.

Namespace

Drupal\Tests\node\Functional

Code

public function testLinkHeader() {
  $node = $this
    ->drupalCreateNode();
  $expected = [
    '<' . Html::escape($node
      ->toUrl('canonical')
      ->setAbsolute()
      ->toString()) . '>; rel="canonical"',
    '<' . Html::escape($node
      ->toUrl('canonical', [
      'alias' => TRUE,
    ])
      ->setAbsolute()
      ->toString()) . '>; rel="shortlink"',
  ];
  $this
    ->drupalGet($node
    ->toUrl());
  $links = $this
    ->getSession()
    ->getResponseHeaders()['Link'];
  $this
    ->assertEquals($expected, $links);
}