function NodeViewTest::testHtmlHeadLinks

Same name and namespace in other branches
  1. 8.9.x core/modules/node/tests/src/Functional/NodeViewTest.php \Drupal\Tests\node\Functional\NodeViewTest::testHtmlHeadLinks()
  2. 10 core/modules/node/tests/src/Functional/NodeViewTest.php \Drupal\Tests\node\Functional\NodeViewTest::testHtmlHeadLinks()
  3. 11.x core/modules/node/tests/src/Functional/NodeViewTest.php \Drupal\Tests\node\Functional\NodeViewTest::testHtmlHeadLinks()

Tests the html head links.

File

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

Class

NodeViewTest
Tests the node/{node} page.

Namespace

Drupal\Tests\node\Functional

Code

public function testHtmlHeadLinks() {
    $node = $this->drupalCreateNode();
    $this->drupalGet($node->toUrl());
    $element = $this->assertSession()
        ->elementExists('css', 'link[rel="canonical"]');
    $this->assertEquals($node->toUrl()
        ->setAbsolute()
        ->toString(), $element->getAttribute('href'));
    $element = $this->assertSession()
        ->elementExists('css', 'link[rel="shortlink"]');
    $this->assertEquals($node->toUrl('canonical', [
        'alias' => TRUE,
    ])
        ->setAbsolute()
        ->toString(), $element->getAttribute('href'));
}

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