function EntityResourceTestBase::getExpectedUnauthorizedAccessMessage

Same name in other branches
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
  2. 10 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()
  3. 11.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::getExpectedUnauthorizedAccessMessage()

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.

... 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 326

Class

EntityResourceTestBase
Defines a base class for testing all entity resources.

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.