function EntityFieldDefaultValueTest::assertDefaultValues

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldDefaultValueTest.php \Drupal\KernelTests\Core\Entity\EntityFieldDefaultValueTest::assertDefaultValues()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityFieldDefaultValueTest.php \Drupal\KernelTests\Core\Entity\EntityFieldDefaultValueTest::assertDefaultValues()
  3. 10 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.

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 50

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, "{$entity_type_id}: Default language");
    $this->assertTrue(Uuid::isValid($entity->uuid->value), "{$entity_type_id}: Default UUID");
    $this->assertEquals([], $entity->name
        ->getValue(), 'Field has one empty value by default.');
}

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