You are here

protected function EntityResourceTestBase::getExpectedUnauthorizedAccessMessage in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
  2. 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

10 calls to EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
BlockContentResourceTestBase::getExpectedUnauthorizedAccessMessage in core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.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.
EntityResourceTestBase::testPatch in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a PATCH request for an entity, plus edge cases to ensure good DX.
EntityResourceTestBase::testPost in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a POST request for an entity, plus edge cases to ensure good DX.

... See full list

17 methods override EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
BlockContentResourceTestBase::getExpectedUnauthorizedAccessMessage in core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.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.
ContactFormResourceTestBase::getExpectedUnauthorizedAccessMessage in core/modules/contact/tests/src/Functional/Rest/ContactFormResourceTestBase.php
Return the expected error message.
EditorResourceTestBase::getExpectedUnauthorizedAccessMessage in core/modules/editor/tests/src/Functional/Rest/EditorResourceTestBase.php
Return the expected error message.
EntityTestLabelResourceTestBase::getExpectedUnauthorizedAccessMessage in core/modules/system/tests/modules/entity_test/tests/src/Functional/Rest/EntityTestLabelResourceTestBase.php
Return the expected error message.

... See full list

File

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

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) {
  $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}.";
}