protected function CookieResourceTestTrait::assertResponseWhenMissingAuthentication in Drupal 9
Same name and namespace in other branches
- 8 core/modules/rest/tests/src/Functional/CookieResourceTestTrait.php \Drupal\Tests\rest\Functional\CookieResourceTestTrait::assertResponseWhenMissingAuthentication()
File
- core/modules/rest/tests/src/Functional/CookieResourceTestTrait.php, line 94
Class
- CookieResourceTestTrait
- Trait for ResourceTestBase subclasses testing $auth=cookie.
Namespace
Drupal\Tests\rest\Functional
Code
protected function assertResponseWhenMissingAuthentication($method, ResponseInterface $response) {
if ($method === 'GET') {
$expected_cookie_403_cacheability = $this
->getExpectedUnauthorizedAccessCacheability()
->addCacheableDependency($this
->getExpectedUnauthorizedEntityAccessCacheability(FALSE));
if (in_array('user.permissions', $expected_cookie_403_cacheability
->getCacheContexts(), TRUE)) {
$expected_cookie_403_cacheability
->addCacheTags([
'config:user.role.anonymous',
]);
}
if (static::$entityTypeId === 'block') {
$expected_cookie_403_cacheability
->setCacheTags(str_replace('user:2', 'user:0', $expected_cookie_403_cacheability
->getCacheTags()));
}
$this
->assertResourceErrorResponse(403, FALSE, $response, $expected_cookie_403_cacheability
->getCacheTags(), $expected_cookie_403_cacheability
->getCacheContexts(), 'MISS', FALSE);
}
else {
$this
->assertResourceErrorResponse(403, FALSE, $response);
}
}