function EntityReferenceItemTest::testContentEntityReferenceItemWithStringId

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::testContentEntityReferenceItemWithStringId()
  2. 8.9.x core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::testContentEntityReferenceItemWithStringId()
  3. 10 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::testContentEntityReferenceItemWithStringId()

Tests referencing content entities with string IDs.

File

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

Class

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

Namespace

Drupal\Tests\field\Kernel\EntityReference

Code

public function testContentEntityReferenceItemWithStringId() : void {
  $entity = EntityTest::create();
  $entity->field_test_entity_test_string_id->target_id = $this->entityStringId
    ->id();
  $entity->save();
  $storage = \Drupal::entityTypeManager()->getStorage('entity_test');
  $storage->resetCache();
  $this->assertEquals($this->entityStringId
    ->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id);
  // Verify that the label for the target ID property definition is correct.
  $label = $entity->field_test_taxonomy_term
    ->getFieldDefinition()
    ->getFieldStorageDefinition()
    ->getPropertyDefinition('target_id')
    ->getLabel();
  $this->assertInstanceOf(TranslatableMarkup::class, $label);
  $this->assertEquals('Taxonomy term ID', $label->render());
}

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