class UuidFormatterTest
Same name and namespace in other branches
- 10 core/modules/field/tests/src/Kernel/KernelString/UuidFormatterTest.php \Drupal\Tests\field\Kernel\KernelString\UuidFormatterTest
- 9 core/modules/field/tests/src/Kernel/String/UuidFormatterTest.php \Drupal\Tests\field\Kernel\String\UuidFormatterTest
- 8.9.x core/modules/field/tests/src/Kernel/String/UuidFormatterTest.php \Drupal\Tests\field\Kernel\String\UuidFormatterTest
Tests the output of a UUID field.
@group field
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\field\Kernel\KernelString\UuidFormatterTest uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of UuidFormatterTest
File
-
core/
modules/ field/ tests/ src/ Kernel/ KernelString/ UuidFormatterTest.php, line 16
Namespace
Drupal\Tests\field\Kernel\KernelStringView source
class UuidFormatterTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'field',
'entity_test',
'system',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installConfig([
'system',
'field',
]);
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->setUpCurrentUser(permissions: [
'view test entity',
]);
}
/**
* Tests string formatter output.
*/
public function testUuidStringFormatter() : void {
$entity = EntityTest::create([]);
$entity->save();
$uuid_field = $entity->get('uuid');
// Verify default render.
$render_array = $uuid_field->view([]);
$this->assertSame($entity->uuid(), $render_array[0]['#context']['value'], '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->assertSame('link', $render_array[0]['#type']);
$this->assertSame($entity->uuid(), $render_array[0]['#title']['#context']['value']);
$this->assertSame($entity->toUrl()
->toString(), $render_array[0]['#url']->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.