function NodeMultiByteUtf8Test::testMultiByteUtf8

Tests that multi-byte UTF-8 characters are stored and retrieved correctly.

File

modules/node/node.test, line 3112

Class

NodeMultiByteUtf8Test
Tests that multi-byte UTF-8 characters are stored and retrieved correctly.

Code

public function testMultiByteUtf8() {
    $connection = Database::getConnection();
    // On MySQL, this test will only run if 'charset' is set to 'utf8mb4' in
    // settings.php.
    if (!($connection->utf8mb4IsSupported() && $connection->utf8mb4IsActive())) {
        return;
    }
    $title = '🐙';
    $this->assertTrue(drupal_strlen($title, 'utf-8') < strlen($title), 'Title has multi-byte characters.');
    $node = $this->drupalCreateNode(array(
        'title' => $title,
    ));
    $this->drupalGet('node/' . $node->nid);
    $result = $this->xpath('//h1[@id="page-title"]');
    $this->assertEqual(trim((string) $result[0]), $title, 'The passed title was returned.');
}

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