You are here

protected function EntityFieldDefaultValueTest::assertDefaultValues in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldDefaultValueTest.php \Drupal\KernelTests\Core\Entity\EntityFieldDefaultValueTest::assertDefaultValues()
  2. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldDefaultValueTest.php \Drupal\KernelTests\Core\Entity\EntityFieldDefaultValueTest::assertDefaultValues()

Executes a test set for a defined entity type.

@internal

Parameters

string $entity_type_id: The entity type to run the tests with.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityFieldDefaultValueTest.php, line 46

Class

EntityFieldDefaultValueTest
Tests default values for entity fields.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function assertDefaultValues(string $entity_type_id) : void {
  $entity = $this->container
    ->get('entity_type.manager')
    ->getStorage($entity_type_id)
    ->create();
  $definition = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  $langcode_key = $definition
    ->getKey('langcode');
  $this
    ->assertEquals('en', $entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Default language', [
    '%entity_type' => $entity_type_id,
  ]));
  $this
    ->assertTrue(Uuid::isValid($entity->uuid->value), new FormattableMarkup('%entity_type: Default UUID', [
    '%entity_type' => $entity_type_id,
  ]));
  $this
    ->assertEquals([], $entity->name
    ->getValue(), 'Field has one empty value by default.');
}