public function RelatedResourceTypesTest::testGetRelatableResourceTypes in JSON:API 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/ResourceType/RelatedResourceTypesTest.php \Drupal\Tests\jsonapi\Kernel\ResourceType\RelatedResourceTypesTest::testGetRelatableResourceTypes()
@covers ::getRelatableResourceTypes @dataProvider getRelatableResourceTypesProvider
File
- tests/
src/ Kernel/ ResourceType/ RelatedResourceTypesTest.php, line 111
Class
- RelatedResourceTypesTest
- @coversDefaultClass \Drupal\jsonapi\ResourceType\ResourceType @coversClass \Drupal\jsonapi\ResourceType\ResourceTypeRepository @group jsonapi
Namespace
Drupal\Tests\jsonapi\Kernel\ResourceTypeCode
public function testGetRelatableResourceTypes($resource_type_name, $relatable_type_names) {
// We're only testing the fields that we set up.
$test_fields = [
'field_ref_foo',
'field_ref_bar',
'field_ref_any',
];
$resource_type = $this->resourceTypeRepository
->getByTypeName($resource_type_name);
// This extracts just the relationship fields under test.
$subjects = array_intersect_key($resource_type
->getRelatableResourceTypes(), array_flip($test_fields));
// Map the related resource type to their type name so we can just compare
// the type names rather that the whole object.
foreach ($test_fields as $field_name) {
if (isset($subjects[$field_name])) {
$subjects[$field_name] = array_map(function ($resource_type) {
return $resource_type
->getTypeName();
}, $subjects[$field_name]);
}
}
$this
->assertArraySubset($relatable_type_names, $subjects);
}