function EntityReferenceItemTest::testContentEntityReferenceItemWithStringId

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::testContentEntityReferenceItemWithStringId()
  2. 10 core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceItemTest::testContentEntityReferenceItemWithStringId()
  3. 11.x 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 250

Class

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

Namespace

Drupal\Tests\field\Kernel\EntityReference

Code

public function testContentEntityReferenceItemWithStringId() {
    $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->assertEqual($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->assertEqual($label->render(), 'Taxonomy term ID');
}

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