Issue #2869387 by tstoeckler, Wim Leers: Subclasses of ResourceTestBase for non-entity resources are required to add pointless code
parent
4342ca29c2
commit
7626a3d70b
|
@ -151,7 +151,6 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
|
|||
// Calculate REST Resource config entity ID.
|
||||
static::$resourceConfigId = 'entity.' . static::$entityTypeId;
|
||||
|
||||
$this->serializer = $this->container->get('serializer');
|
||||
$this->entityStorage = $this->container->get('entity_type.manager')
|
||||
->getStorage(static::$entityTypeId);
|
||||
|
||||
|
@ -231,7 +230,7 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
|
|||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return $this->getExpectedBCUnauthorizedAccessMessage($method);
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
$permission = $this->entity->getEntityType()->getAdminPermission();
|
||||
|
@ -255,13 +254,6 @@ abstract class EntityResourceTestBase extends ResourceTestBase {
|
|||
return "$message.";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedBcUnauthorizedAccessMessage($method) {
|
||||
return "The 'restful " . strtolower($method) . " entity:" . $this->entity->getEntityTypeId() . "' permission is required.";
|
||||
}
|
||||
|
||||
/**
|
||||
* The expected cache tags for the GET/HEAD response of the test entity.
|
||||
*
|
||||
|
|
|
@ -62,6 +62,8 @@ abstract class ResourceTestBase extends BrowserTestBase {
|
|||
* The REST Resource plugin ID can be calculated from this.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @see \Drupal\rest\Entity\RestResourceConfig::__construct()
|
||||
*/
|
||||
protected static $resourceConfigId = NULL;
|
||||
|
||||
|
@ -99,6 +101,8 @@ abstract class ResourceTestBase extends BrowserTestBase {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->serializer = $this->container->get('serializer');
|
||||
|
||||
// Ensure the anonymous user role has no permissions at all.
|
||||
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
|
||||
foreach ($user_role->getPermissions() as $permission) {
|
||||
|
@ -172,6 +176,21 @@ abstract class ResourceTestBase extends BrowserTestBase {
|
|||
\Drupal::service('router.builder')->rebuildIfNeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the expected error message.
|
||||
*
|
||||
* @param string $method
|
||||
* The HTTP method (GET, POST, PATCH, DELETE).
|
||||
*
|
||||
* @return string
|
||||
* The error string.
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
$resource_plugin_id = str_replace('.', ':', static::$resourceConfigId);
|
||||
$permission = 'restful ' . strtolower($method) . ' ' . $resource_plugin_id;
|
||||
return "The '$permission' permission is required.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the necessary authorization.
|
||||
*
|
||||
|
@ -230,29 +249,6 @@ abstract class ResourceTestBase extends BrowserTestBase {
|
|||
*/
|
||||
abstract protected function assertAuthenticationEdgeCases($method, Url $url, array $request_options);
|
||||
|
||||
/**
|
||||
* Return the expected error message.
|
||||
*
|
||||
* @param string $method
|
||||
* The HTTP method (GET, POST, PATCH, DELETE).
|
||||
*
|
||||
* @return string
|
||||
* The error string.
|
||||
*/
|
||||
abstract protected function getExpectedUnauthorizedAccessMessage($method);
|
||||
|
||||
/**
|
||||
* Return the default expected error message if the
|
||||
* bc_entity_resource_permissions is true.
|
||||
*
|
||||
* @param string $method
|
||||
* The HTTP method (GET, POST, PATCH, DELETE).
|
||||
*
|
||||
* @return string
|
||||
* The error string.
|
||||
*/
|
||||
abstract protected function getExpectedBcUnauthorizedAccessMessage($method);
|
||||
|
||||
/**
|
||||
* Initializes authentication.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue