diff --git a/core/modules/config/src/Tests/ConfigEntityListTest.php b/core/modules/config/src/Tests/ConfigEntityListTest.php index e9950ea424..cb0c730b33 100644 --- a/core/modules/config/src/Tests/ConfigEntityListTest.php +++ b/core/modules/config/src/Tests/ConfigEntityListTest.php @@ -29,6 +29,8 @@ protected function setUp() { // test. \Drupal::entityManager()->getStorage('config_test')->load('override')->delete(); $this->drupalPlaceBlock('local_actions_block'); + + $this->drupalLogin($this->createUser(['view config_test', 'administer config_test'])); } /** @@ -149,7 +151,7 @@ public function testList() { */ public function testListUI() { // Log in as an administrative user to access the full menu trail. - $this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer site configuration'])); + $this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer site configuration', 'administer config_test'])); // Get the list callback page. $this->drupalGet('admin/structure/config_test'); diff --git a/core/modules/rest/tests/modules/config_test_rest/config_test_rest.module b/core/modules/rest/tests/modules/config_test_rest/config_test_rest.module index fcd9979a11..0cffb9c1f4 100644 --- a/core/modules/rest/tests/modules/config_test_rest/config_test_rest.module +++ b/core/modules/rest/tests/modules/config_test_rest/config_test_rest.module @@ -26,5 +26,8 @@ function config_test_rest_config_test_access(EntityInterface $entity, $operation // Add permission, so that EntityResourceTestBase's scenarios can test access // being denied. By default, all access is always allowed for the config_test // config entity. - return AccessResult::forbiddenIf(!$account->hasPermission('view config_test'))->cachePerPermissions(); + if ($operation === 'view') { + return AccessResult::forbiddenIf(!$account->hasPermission('view config_test'))->cachePerPermissions(); + } + return AccessResult::neutral(); } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php index f5f83dab62..1ec31a5ea3 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php @@ -113,15 +113,7 @@ protected function getExpectedUnauthorizedAccessMessage($method) { if ($method === 'GET') { return 'You are not authorized to view this config_test entity.'; } - elseif ($method === 'PATCH') { - return 'You are not authorized to update this config_test entity.'; - } - elseif ($method === 'DELETE') { - return 'You are not authorized to delete this config_test entity.'; - } - else { - return "The 'administer config_test' permission is required."; - } + return "The 'administer config_test' permission is required."; } } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index dc76c6608d..9d4fbf799c 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -75,7 +75,7 @@ * * @var string[] */ - protected static $patchProtectedFieldNames; + protected static $patchProtectedFieldNames = []; /** * Optionally specify which field is the 'label' field. Some entities specify @@ -967,10 +967,12 @@ public function testPatch() { $response = $this->request('PATCH', $url, $request_options); $this->assertResourceResponse(200, FALSE, $response); $this->assertFalse($response->hasHeader('X-Drupal-Cache')); - // Ensure that fields do not get deleted if they're not present in the PATCH - // request. Test this using the configurable field that we added, but which - // is not sent in the PATCH request. - $this->assertSame('All the faith he had had had had no effect on the outcome of his life.', $this->entityStorage->loadUnchanged($this->entity->id())->get('field_rest_test')->value); + if ($this->entity instanceof FieldableEntityInterface) { + // Ensure that fields do not get deleted if they're not present in the PATCH + // request. Test this using the configurable field that we added, but which + // is not sent in the PATCH request. + $this->assertSame('All the faith he had had had had no effect on the outcome of his life.', $this->entityStorage->loadUnchanged($this->entity->id())->get('field_rest_test')->value); + } $this->config('rest.settings')->set('bc_entity_resource_permissions', TRUE)->save(TRUE);