protected function EntityResourceTestBase::getExpectedUnauthorizedAccessMessage in Drupal 9
Same name and namespace in other branches
- 8 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
Return the expected error message.
Parameters
string $method: The HTTP method (GET, POST, PATCH, DELETE).
Return value
string The error string.
Overrides ResourceTestBase::getExpectedUnauthorizedAccessMessage
24 calls to EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
- BlockContentResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
modules/ block_content/ tests/ src/ Functional/ Rest/ BlockContentResourceTestBase.php - Return the expected error message.
- BlockResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
modules/ block/ tests/ src/ Functional/ Rest/ BlockResourceTestBase.php - Return the expected error message.
- ConfigTestResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
modules/ config/ tests/ config_test/ tests/ src/ Functional/ Rest/ ConfigTestResourceTestBase.php - Return the expected error message.
- EntityResourceTestBase::testDelete in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ EntityResourceTestBase.php - Tests a DELETE request for an entity, plus edge cases to ensure good DX.
- EntityResourceTestBase::testGet in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ EntityResourceTestBase.php - Tests a GET request for an entity, plus edge cases to ensure good DX.
32 methods override EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
- BaseFieldOverrideResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
tests/ Drupal/ FunctionalTests/ Rest/ BaseFieldOverrideResourceTestBase.php - Return the expected error message.
- BlockContentResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
modules/ block_content/ tests/ src/ Functional/ Rest/ BlockContentResourceTestBase.php - Return the expected error message.
- BlockResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
modules/ block/ tests/ src/ Functional/ Rest/ BlockResourceTestBase.php - Return the expected error message.
- CommentResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
modules/ comment/ tests/ src/ Functional/ Rest/ CommentResourceTestBase.php - Return the expected error message.
- ConfigTestResourceTestBase::getExpectedUnauthorizedAccessMessage in core/
modules/ config/ tests/ config_test/ tests/ src/ Functional/ Rest/ ConfigTestResourceTestBase.php - Return the expected error message.
File
- core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ EntityResourceTestBase.php, line 327
Class
- EntityResourceTestBase
- Even though there is the generic EntityResource, it's necessary for every entity type to have its own test, because they each have different fields, validation constraints, et cetera. It's not because the generic case works, that every case…
Namespace
Drupal\Tests\rest\Functional\EntityResourceCode
protected function getExpectedUnauthorizedAccessMessage($method) {
$permission = $this->entity
->getEntityType()
->getAdminPermission();
if ($permission !== FALSE) {
return "The '{$permission}' permission is required.";
}
$http_method_to_entity_operation = [
'GET' => 'view',
'POST' => 'create',
'PATCH' => 'update',
'DELETE' => 'delete',
];
$operation = $http_method_to_entity_operation[$method];
$message = sprintf('You are not authorized to %s this %s entity', $operation, $this->entity
->getEntityTypeId());
if ($this->entity
->bundle() !== $this->entity
->getEntityTypeId()) {
$message .= ' of bundle ' . $this->entity
->bundle();
}
return "{$message}.";
}