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. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldDefaultValueTest.php \Drupal\KernelTests\Core\Entity\EntityFieldDefaultValueTest::assertDefaultValues()
  3. 11.x 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->assertEqual($entity->{$langcode_key}->value, 'en', 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->assertEqual($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.