You are here

protected function EntityFieldDefaultValueTest::assertDefaultValues in Drupal 9

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

Executes a test set for a defined entity type.

Parameters

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

1 call to EntityFieldDefaultValueTest::assertDefaultValues()
EntityFieldDefaultValueTest::testDefaultValues in core/tests/Drupal/KernelTests/Core/Entity/EntityFieldDefaultValueTest.php
Tests default values on entities and fields.

File

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

Class

EntityFieldDefaultValueTest
Tests default values for entity fields.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function assertDefaultValues($entity_type_id) {
  $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.');
}