You are here

public function EntityDescriptionTest::testEntityDescription in Lightning Core 8.3

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/EntityDescriptionTest.php \Drupal\Tests\lightning_core\Kernel\EntityDescriptionTest::testEntityDescription()
  2. 8 tests/src/Kernel/EntityDescriptionTest.php \Drupal\Tests\lightning_core\Kernel\EntityDescriptionTest::testEntityDescription()
  3. 8.2 tests/src/Kernel/EntityDescriptionTest.php \Drupal\Tests\lightning_core\Kernel\EntityDescriptionTest::testEntityDescription()
  4. 8.4 tests/src/Kernel/EntityDescriptionTest.php \Drupal\Tests\lightning_core\Kernel\EntityDescriptionTest::testEntityDescription()

Tests entity description functionality for an entity type.

@dataProvider provider

Parameters

string $entity_type_id: The entity type ID.

array $values: (optional) Values with which to create the entity.

string $form_operation: (optional) The entity form operation that exposes the description field. Defaults to 'default'.

File

tests/src/Kernel/EntityDescriptionTest.php, line 45

Class

EntityDescriptionTest
@group lightning_core

Namespace

Drupal\Tests\lightning_core\Kernel

Code

public function testEntityDescription($entity_type_id, array $values = [], $form_operation = 'default') {
  $entity = $this->container
    ->get('entity_type.manager')
    ->getStorage($entity_type_id)
    ->create($values);
  $this
    ->assertInstanceOf(EntityDescriptionInterface::class, $entity);

  /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\EntityDescriptionInterface $entity */
  $description = $this
    ->randomString(32);
  $this
    ->assertEmpty($entity
    ->getDescription());
  $entity
    ->setDescription($description);
  $this
    ->assertEquals($description, $entity
    ->getDescription());

  // If the entity type has a form for the provided form operation, build the
  // form and assert that it has a description field with the correct default
  // value.
  if ($entity
    ->getEntityType()
    ->getFormClass($form_operation)) {
    $form = $this->container
      ->get('entity.form_builder')
      ->getForm($entity, $form_operation);
    $this
      ->assertInternalType('array', $form['description']);
    $this
      ->assertEquals($description, $form['description']['#default_value']);
  }
}