public function UserTest::testQueryInvolvingRoles in Drupal 9
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testQueryInvolvingRoles()
- 10 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testQueryInvolvingRoles()
Tests good error DX when trying to filter users by role.
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ UserTest.php, line 432
Class
- UserTest
- JSON:API integration test for the "User" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testQueryInvolvingRoles() {
$this
->setUpAuthorization('GET');
$collection_url = Url::fromRoute('jsonapi.user--user.collection', [], [
'query' => [
'filter[roles.id][value]' => 'e9b1de3f-9517-4c27-bef0-0301229de792',
],
]);
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$request_options = NestedArray::mergeDeep($request_options, $this
->getAuthenticationRequestOptions());
// The 'administer users' permission is required to filter by role entities.
$this
->grantPermissionsToTestedRole([
'administer users',
]);
$response = $this
->request('GET', $collection_url, $request_options);
$expected_cache_contexts = [
'url.path',
'url.query_args:filter',
'url.site',
];
$this
->assertResourceErrorResponse(400, "Filtering on config entities is not supported by Drupal's entity API. You tried to filter on a Role config entity.", $collection_url, $response, FALSE, [
'4xx-response',
'http_response',
], $expected_cache_contexts, FALSE, 'MISS');
}