.../MenuLinkContentHalJsonBasicAuthTest.php | 1 - .../src/MenuLinkContentAccessControlHandler.php | 2 +- .../MenuLinkContentJsonBasicAuthTest.php | 1 - .../MenuLinkContentJsonCookieTest.php | 5 - .../MenuLinkContentResourceTestBase.php | 178 +++++++++++---------- 5 files changed, 98 insertions(+), 89 deletions(-) diff --git a/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonBasicAuthTest.php index eb5e705..3af8362 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonBasicAuthTest.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonBasicAuthTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\hal\Functional\EntityResource\MenuLinkContent; -use Drupal\Tests\hal\Functional\EntityResource\MenuLinkContent\MenuLinkContentHalJsonAnonTest; use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; /** diff --git a/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php b/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php index c9771d4..c69349e 100644 --- a/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php +++ b/core/modules/menu_link_content/src/MenuLinkContentAccessControlHandler.php @@ -56,7 +56,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter case 'update': if (!$account->hasPermission('administer menu')) { - return AccessResult::neutral()->cachePerPermissions(); + return AccessResult::neutral("The 'administer menu' permission is required.")->cachePerPermissions(); } else { // If there is a URL, this is an external link so always accessible. diff --git a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonBasicAuthTest.php b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonBasicAuthTest.php index 9be9e55..952088b 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonBasicAuthTest.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonBasicAuthTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\rest\Functional\EntityResource\MenuLinkContent; use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; -use Drupal\Tests\rest\Functional\JsonBasicAuthWorkaroundFor2805281Trait; /** * @group rest diff --git a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonCookieTest.php b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonCookieTest.php index 155b853..73b4567 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonCookieTest.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentJsonCookieTest.php @@ -1,10 +1,5 @@ [ [ 'value' => 'menu_link_content', - ] - ] + ], + ], ]; } @@ -93,85 +93,101 @@ protected function getNormalizedPostEntity() { */ protected function getExpectedNormalizedEntity() { return [ - 'uuid' => [ - [ - 'value' => $this->entity->uuid(), - ], - ], - 'id' => [ - [ - 'value' => '1', - ], - ], - 'title' => [ - [ - 'value' => 'Llama Gabilondo', - ], - ], - 'link' => [ - [ - 'uri' => 'https://nl.wikipedia.org/wiki/Llama', - 'title' => NULL, - 'options' => [], - ], - ], - 'weight' => [ - [ - 'value' => 0, - ], - ], - 'menu_name' => [ - [ - 'value' => 'main', - ], - ], - 'langcode' => [ - [ - 'value' => 'en', - ], - ], - 'bundle' => [ - [ - 'value' => 'menu_link_content', - ], - ], - 'description' => [ - [ - 'value' => 'Llama Gabilondo', - ], - ], - 'external' => [ - [ - 'value' => '0', - ], - ], - 'rediscover' => [ - [ - 'value' => '0', - ], - ], - 'expanded' => [ - [ - 'value' => '0', - ], - ], - 'enabled' => [ - [ - 'value' => TRUE, - ], - ], - 'changed' => [ - [ - 'value' => $this->entity->getChangedTime(), - ], - ], - 'default_langcode' => [ - [ - 'value' => '1', - ], - ], + 'uuid' => [ + [ + 'value' => $this->entity->uuid(), + ], + ], + 'id' => [ + [ + 'value' => '1', + ], + ], + 'title' => [ + [ + 'value' => 'Llama Gabilondo', + ], + ], + 'link' => [ + [ + 'uri' => 'https://nl.wikipedia.org/wiki/Llama', + 'title' => NULL, + 'options' => [], + ], + ], + 'weight' => [ + [ + 'value' => 0, + ], + ], + 'menu_name' => [ + [ + 'value' => 'main', + ], + ], + 'langcode' => [ + [ + 'value' => 'en', + ], + ], + 'bundle' => [ + [ + 'value' => 'menu_link_content', + ], + ], + 'description' => [ + [ + 'value' => 'Llama Gabilondo', + ], + ], + 'external' => [ + [ + 'value' => '0', + ], + ], + 'rediscover' => [ + [ + 'value' => '0', + ], + ], + 'expanded' => [ + [ + 'value' => '0', + ], + ], + 'enabled' => [ + [ + 'value' => TRUE, + ], + ], + 'changed' => [ + [ + 'value' => $this->entity->getChangedTime(), + ], + ], + 'default_langcode' => [ + [ + 'value' => '1', + ], + ], 'parent' => [], - ]; + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { + return parent::getExpectedUnauthorizedAccessMessage($method); + } + + switch ($method) { + case 'DELETE': + return "You are not authorized to delete this menu_link_content entity."; + default: + return parent::getExpectedUnauthorizedAccessMessage($method); + } } }