function NodeViewTest::testMultiByteUtf8

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

Tests that we store and retrieve multi-byte UTF-8 characters correctly.

File

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

Class

NodeViewTest
Tests the node/{node} page.

Namespace

Drupal\Tests\node\Functional

Code

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);
}

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