NodeViewTest.php

Same filename in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeViewTest.php
  2. 8.9.x core/modules/node/tests/src/Functional/NodeViewTest.php
  3. 11.x core/modules/node/tests/src/Functional/NodeViewTest.php

Namespace

Drupal\Tests\node\Functional

File

core/modules/node/tests/src/Functional/NodeViewTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\node\Functional;


/**
 * Tests the node/{node} page.
 *
 * @group node
 * @see \Drupal\node\Controller\NodeController
 */
class NodeViewTest extends NodeTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests the html head links.
     */
    public function testHtmlHeadLinks() : void {
        $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'));
    }
    
    /**
     * Tests the Link header.
     */
    public function testLinkHeader() : void {
        $node = $this->drupalCreateNode();
        $this->drupalGet($node->toUrl());
        $this->assertArrayNotHasKey('Link', $this->getSession()
            ->getResponseHeaders());
    }
    
    /**
     * Tests that we store and retrieve multi-byte UTF-8 characters correctly.
     */
    public function testMultiByteUtf8() : void {
        $title = '🐝';
        // To ensure that the title has multi-byte characters, we compare the byte
        // length to the character length.
        $this->assertLessThan(strlen($title), mb_strlen($title, 'utf-8'));
        $node = $this->drupalCreateNode([
            'title' => $title,
        ]);
        $this->drupalGet($node->toUrl());
        // Verify that the passed title was returned.
        $this->assertSession()
            ->elementTextEquals('xpath', '//h1/span', $title);
    }

}

Classes

Title Deprecated Summary
NodeViewTest Tests the node/{node} page.

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