public function DynamicEntityReferenceConfigEntityTest::testMixedConfigurableField in Dynamic Entity Reference 8.2
Content entity (int ID) and config entity configurable DER field.
File
- tests/
src/ Kernel/ DynamicEntityReferenceConfigEntityTest.php, line 157
Class
- DynamicEntityReferenceConfigEntityTest
- Tests for referencing configuration entities with configurable fields.
Namespace
Drupal\Tests\dynamic_entity_reference\KernelCode
public function testMixedConfigurableField() {
$this->referencedEntityTypes[] = 'entity_test_rev';
$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.
$entity = $this->container
->get('entity_type.manager')
->getStorage($this->entityType)
->create([
'type' => $this->bundle,
]);
$entity->{$this->fieldName}->target_type = $this->contentEntityReference
->getEntityTypeId();
$entity->{$this->fieldName}->target_id = $this->contentEntityReference
->id();
$violations = $entity->{$this->fieldName}
->validate();
$this
->assertEmpty($violations
->count(), 'Validation passes.');
}