diff --git a/tests/src/Functional/BlockTest.php b/tests/src/Functional/BlockTest.php index e7786fa..7379de9 100644 --- a/tests/src/Functional/BlockTest.php +++ b/tests/src/Functional/BlockTest.php @@ -156,7 +156,7 @@ class BlockTest extends ResourceTestBase { protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'GET': - return ''; + return "The block visibility condition 'user_role' denied access."; default: return parent::getExpectedUnauthorizedAccessMessage($method); diff --git a/tests/src/Functional/ConfigTestTest.php b/tests/src/Functional/ConfigTestTest.php index 64fd91f..e6d873d 100644 --- a/tests/src/Functional/ConfigTestTest.php +++ b/tests/src/Functional/ConfigTestTest.php @@ -41,6 +41,19 @@ class ConfigTestTest extends ResourceTestBase { $this->grantPermissionsToTestedRole(['view config_test']); } + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + switch ($method) { + case 'GET': + return "The 'view config_test' permission is required."; + + default: + return parent::getExpectedUnauthorizedAccessMessage($method); + } + } + /** * {@inheritdoc} */ diff --git a/tests/src/Functional/ResourceTestBase.php b/tests/src/Functional/ResourceTestBase.php index c04e32f..9dbcd83 100644 --- a/tests/src/Functional/ResourceTestBase.php +++ b/tests/src/Functional/ResourceTestBase.php @@ -910,25 +910,8 @@ abstract class ResourceTestBase extends BrowserTestBase { if (!static::$anonymousUsersCanViewLabels) { $expected_403_cacheability = $this->getExpectedUnauthorizedAccessCacheability(); $reason = $this->getExpectedUnauthorizedAccessMessage('GET'); - // @todo Remove $expected + assertResourceResponse() in favor of the commented line below once https://www.drupal.org/project/jsonapi/issues/2943176 lands. - $expected_document = [ - 'jsonapi' => static::$jsonApiMember, - 'errors' => [ - [ - 'title' => 'Forbidden', - 'status' => 403, - 'detail' => "The current user is not allowed to GET the selected resource." . (strlen($reason) ? ' ' . $reason : ''), - 'links' => [ - 'info' => ['href' => HttpExceptionNormalizer::getInfoUrl(403)], - 'via' => ['href' => $url->setAbsolute()->toString()], - ], - 'source' => [ - 'pointer' => '/data', - ], - ], - ], - ]; - $this->assertResourceResponse(403, $expected_document, $response, $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), FALSE, 'MISS'); + $message = trim("The current user is not allowed to GET the selected resource. $reason"); + $this->assertResourceErrorResponse(403, $message, $url, $response, '/data', $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), FALSE, 'MISS'); $this->assertArrayNotHasKey('Link', $response->getHeaders()); } else { diff --git a/tests/src/Functional/ShortcutSetTest.php b/tests/src/Functional/ShortcutSetTest.php index 6322abd..0ab41a3 100644 --- a/tests/src/Functional/ShortcutSetTest.php +++ b/tests/src/Functional/ShortcutSetTest.php @@ -54,6 +54,19 @@ class ShortcutSetTest extends ResourceTestBase { } } + /** + * {@inheritdoc} + */ + protected function getExpectedUnauthorizedAccessMessage($method) { + switch ($method) { + case 'GET': + return "The 'access shortcuts' permission is required."; + + default: + return parent::getExpectedUnauthorizedAccessMessage($method); + } + } + /** * {@inheritdoc} */