public function DynamicEntityReferenceConfigEntityTest::testMixedConfigurableFieldStringId in Dynamic Entity Reference 8.2
String-ID content entity and config entity.
File
- tests/
src/ Kernel/ DynamicEntityReferenceConfigEntityTest.php, line 183
Class
- DynamicEntityReferenceConfigEntityTest
- Tests for referencing configuration entities with configurable fields.
Namespace
Drupal\Tests\dynamic_entity_reference\KernelCode
public function testMixedConfigurableFieldStringId() {
$this->referencedEntityTypes[] = 'entity_test_string_id';
$this
->setUpField();
// Check config entity.
$entity = $this->container
->get('entity_type.manager')
->getStorage($this->entityType)
->create([
'type' => $this->bundle,
]);
$entity->{$this->fieldName}->target_type = $this->configTestReference
->getEntityTypeId();
$entity->{$this->fieldName}->target_id = $this->configTestReference
->id();
$violations = $entity->{$this->fieldName}
->validate();
$this
->assertEmpty($violations
->count(), 'Validation passes.');
// Check content entity (string ID).
$referenced_entity = $this->container
->get('entity_type.manager')
->getStorage('entity_test_string_id')
->create([
'type' => $this->bundle,
]);
$entity = $this->container
->get('entity_type.manager')
->getStorage($this->entityType)
->create([
'type' => $this->bundle,
]);
$entity->{$this->fieldName}->target_type = $referenced_entity
->getEntityTypeId();
$entity->{$this->fieldName}->target_id = $referenced_entity
->id();
$violations = $entity->{$this->fieldName}
->validate();
$this
->assertEmpty($violations
->count(), 'Validation passes.');
}