You are here

protected function EntityResourceTestBase::getExpectedUnauthorizedAccessMessage in Drupal 8

Same name and namespace in other branches
  1. 9 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

36 calls to 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.

... See full list

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.

... See full list

File

core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php, line 344

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\EntityResource

Code

protected function getExpectedUnauthorizedAccessMessage($method) {
  if ($this
    ->config('rest.settings')
    ->get('bc_entity_resource_permissions')) {
    return parent::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}.";
}