function RelatedResourceTypesTest::testGetRelatableResourceTypesFromFieldDefinition
Same name in other branches
- 10 core/modules/jsonapi/tests/src/Kernel/ResourceType/RelatedResourceTypesTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\RelatedResourceTypesTest::testGetRelatableResourceTypesFromFieldDefinition()
- 11.x core/modules/jsonapi/tests/src/Kernel/ResourceType/RelatedResourceTypesTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\RelatedResourceTypesTest::testGetRelatableResourceTypesFromFieldDefinition()
Ensure a graceful failure when a field can references a missing bundle.
@covers \Drupal\jsonapi\ResourceType\ResourceTypeRepository::all @covers \Drupal\jsonapi\ResourceType\ResourceTypeRepository::calculateRelatableResourceTypes @covers \Drupal\jsonapi\ResourceType\ResourceTypeRepository::getRelatableResourceTypesFromFieldDefinition
@link https://www.drupal.org/project/drupal/issues/2996114
File
-
core/
modules/ jsonapi/ tests/ src/ Kernel/ ResourceType/ RelatedResourceTypesTest.php, line 192
Class
- RelatedResourceTypesTest
- @coversDefaultClass \Drupal\jsonapi\ResourceType\ResourceType @coversClass \Drupal\jsonapi\ResourceType\ResourceTypeRepository @group jsonapi
Namespace
Drupal\Tests\jsonapi\Kernel\ResourceTypeCode
public function testGetRelatableResourceTypesFromFieldDefinition() {
$field_config_storage = $this->container
->get('entity_type.manager')
->getStorage('field_config');
static::assertCount(0, $this->resourceTypeRepository
->get('node', 'foo')
->getRelatableResourceTypesByField('field_relationship'));
$this->createEntityReferenceField('node', 'foo', 'field_ref_with_missing_bundle', 'Related entity', 'node', 'default', [
'target_bundles' => [
'missing_bundle',
],
]);
$fields = $field_config_storage->loadByProperties([
'field_name' => 'field_ref_with_missing_bundle',
]);
static::assertSame([
'missing_bundle',
], $fields['node.foo.field_ref_with_missing_bundle']->getItemDefinition()
->getSetting('handler_settings')['target_bundles']);
try {
$this->resourceTypeRepository
->get('node', 'foo')
->getRelatableResourceTypesByField('field_ref_with_missing_bundle');
static::fail('The above code must produce a warning since the "missing_bundle" does not exist.');
} catch (Warning $e) {
static::assertSame('The "field_ref_with_missing_bundle" at "node:foo" references the "node:missing_bundle" entity type that does not exist. Please take action.', $e->getMessage());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.