function UuidFormatterTest::testUuidStringFormatter

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/String/UuidFormatterTest.php \Drupal\Tests\field\Kernel\String\UuidFormatterTest::testUuidStringFormatter()
  2. 10 core/modules/field/tests/src/Kernel/KernelString/UuidFormatterTest.php \Drupal\Tests\field\Kernel\KernelString\UuidFormatterTest::testUuidStringFormatter()
  3. 11.x core/modules/field/tests/src/Kernel/KernelString/UuidFormatterTest.php \Drupal\Tests\field\Kernel\KernelString\UuidFormatterTest::testUuidStringFormatter()

Tests string formatter output.

File

core/modules/field/tests/src/Kernel/String/UuidFormatterTest.php, line 37

Class

UuidFormatterTest
Tests the output of a UUID field.

Namespace

Drupal\Tests\field\Kernel\String

Code

public function testUuidStringFormatter() {
    $entity = EntityTest::create([]);
    $entity->save();
    $uuid_field = $entity->get('uuid');
    // Verify default render.
    $render_array = $uuid_field->view([]);
    $this->assertIdentical($render_array[0]['#context']['value'], $entity->uuid(), 'The rendered UUID matches the entity UUID.');
    $this->assertStringContainsString($entity->uuid(), $this->render($render_array), 'The rendered UUID found.');
    // Verify customized render.
    $render_array = $uuid_field->view([
        'settings' => [
            'link_to_entity' => TRUE,
        ],
    ]);
    $this->assertIdentical($render_array[0]['#type'], 'link');
    $this->assertIdentical($render_array[0]['#title']['#context']['value'], $entity->uuid());
    $this->assertIdentical($render_array[0]['#url']->toString(), $entity->toUrl()
        ->toString());
    $rendered = $this->render($render_array);
    $this->assertStringContainsString($entity->uuid(), $rendered, 'The rendered UUID found.');
    $this->assertStringContainsString($entity->toUrl()
        ->toString(), $rendered, 'The rendered entity URL found.');
}

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