$filtered_collection_url->
setOption('query',
$entity_collection_filter +
$default_sort);
$expected_response =
$this->
getExpectedCollectionResponse($filtered_entity_collection,
$filtered_collection_url->
toString(),
$request_options, NULL, TRUE
);
$expected_cacheability =
$expected_response->
getCacheableMetadata();
$expected_document =
$expected_response->
getResponseData();
$response =
$this->
request('GET',
$filtered_collection_url,
$request_options);
// MISS or UNCACHEABLE depends on the collection data. It must not be HIT.
$dynamic_cache =
$expected_cacheability->
getCacheMaxAge() === 0 || !
empty(array_intersect(['user', 'session'
],
$expected_cacheability->
getCacheContexts())) ? 'UNCACHEABLE' : 'MISS';
$this->
assertResourceResponse(200,
$expected_document,
$response,
$expected_cacheability->
getCacheTags(),
$expected_cacheability->
getCacheContexts(), FALSE,
$dynamic_cache);
// Filtered collection with includes.
$relationship_field_names =
array_reduce($filtered_entity_collection,
function D
$relationship_field_names,
$entity) { return array_unique(array_merge($relationship_field_names,
$this->
getRelationshipFieldNames($entity)));
},
[]);
$include =
['include' =>
implode(',',
$relationship_field_names)];
$filtered_collection_include_url =
clone $collection_url;
$filtered_collection_include_url->
setOption('query',
$entity_collection_filter +
$include +
$default_sort);
$expected_response =
$this->
getExpectedCollectionResponse($filtered_entity_collection,
$filtered_collection_include_url->
toString(),
$request_options,
$relationship_field_names, TRUE
);
$expected_cacheability =
$expected_response->
getCacheableMetadata();
$expected_cacheability->
setCacheTags(array_values(array_diff($expected_cacheability->
getCacheTags(),
['4xx-response'
])));
$expected_document =
$expected_response->
getResponseData();
$response =
$this->
request('GET',
$filtered_collection_include_url,
$request_options);
// MISS or UNCACHEABLE depends on the included data. It must not be HIT.
$dynamic_cache =
$expected_cacheability->
getCacheMaxAge() === 0 || !
empty(array_intersect(['user', 'session'
],
$expected_cacheability->
getCacheContexts())) ? 'UNCACHEABLE' : 'MISS';