You are here

public function EntityReferenceItemTest::testGenerateSampleValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::testGenerateSampleValue()

Tests the ::generateSampleValue() method.

File

core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php, line 219

Class

EntityReferenceItemTest
Tests the new entity API for the entity reference field type.

Namespace

Drupal\Tests\field\Kernel\EntityReference

Code

public function testGenerateSampleValue() {
  $entity = EntityTest::create();

  // Test while a term exists.
  $entity->field_test_taxonomy_term
    ->generateSampleItems();
  $this
    ->assertInstanceOf(TermInterface::class, $entity->field_test_taxonomy_term->entity);
  $this
    ->entityValidateAndSave($entity);

  // Delete the term and test again.
  $this->term
    ->delete();
  $entity->field_test_taxonomy_term
    ->generateSampleItems();
  $this
    ->assertInstanceOf(TermInterface::class, $entity->field_test_taxonomy_term->entity);
  $this
    ->entityValidateAndSave($entity);
}