function EntityReferenceFieldTest::testTargetEntityTypeMissing
Same name and namespace in other branches
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceFieldTest.php \Drupal\KernelTests\Core\Entity\EntityReferenceFieldTest::testTargetEntityTypeMissing()
Tests exception thrown with a missing target entity type.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityReferenceFieldTest.php, line 377
Class
- EntityReferenceFieldTest
- Tests for the entity reference field.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testTargetEntityTypeMissing() : void {
// Setup a test entity type with an entity reference field to an entity type
// that doesn't exist.
$definitions = [
'bad_reference' => BaseFieldDefinition::create('entity_reference')->setSetting('target_type', 'made_up_entity_type')
->setSetting('handler', 'default'),
];
$this->state
->set('entity_test.additional_base_field_definitions', $definitions);
$this->entityTypeManager
->clearCachedDefinitions();
$this->expectException(FieldException::class);
$this->expectExceptionMessage("Field 'bad_reference' on entity type 'entity_test' references a target entity type 'made_up_entity_type' which does not exist.");
$this->installEntitySchema('entity_test');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.