function EntityReferenceIntegrationTest::assertFieldValues

Same name in other branches
  1. 9 core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceIntegrationTest::assertFieldValues()
  2. 8.9.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceIntegrationTest::assertFieldValues()
  3. 11.x core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php \Drupal\Tests\field\Functional\EntityReference\EntityReferenceIntegrationTest::assertFieldValues()

Asserts that the reference field values are correct.

@internal

Parameters

string $entity_name: The name of the test entity.

\Drupal\Core\Entity\EntityInterface[] $referenced_entities: An array of referenced entities.

1 call to EntityReferenceIntegrationTest::assertFieldValues()
EntityReferenceIntegrationTest::testSupportedEntityTypesAndWidgets in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php
Tests the entity reference field with all its supported field widgets.

File

core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php, line 202

Class

EntityReferenceIntegrationTest
Tests various Entity reference UI components.

Namespace

Drupal\Tests\field\Functional\EntityReference

Code

protected function assertFieldValues(string $entity_name, array $referenced_entities) : void {
    $entity = current($this->container
        ->get('entity_type.manager')
        ->getStorage($this->entityType)
        ->loadByProperties([
        'name' => $entity_name,
    ]));
    $this->assertNotEmpty($entity, "{$this->entityType}: Entity found in the database.");
    $this->assertEquals($referenced_entities[0]->id(), $entity->{$this->fieldName}->target_id);
    $this->assertEquals($referenced_entities[0]->id(), $entity->{$this->fieldName}->entity
        ->id());
    $this->assertEquals($referenced_entities[0]->label(), $entity->{$this->fieldName}->entity
        ->label());
    $this->assertEquals($referenced_entities[1]->id(), $entity->{$this->fieldName}[1]->target_id);
    $this->assertEquals($referenced_entities[1]->id(), $entity->{$this->fieldName}[1]->entity
        ->id());
    $this->assertEquals($referenced_entities[1]->label(), $entity->{$this->fieldName}[1]->entity
        ->label());
}

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