public function UserTest::testQueryInvolvingRoles in JSON:API 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testQueryInvolvingRoles()
Test good error DX when trying to filter users by role.
File
- tests/
src/ Functional/ UserTest.php, line 458
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.uuid][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);
$this
->assertResourceErrorResponse(400, "Filtering on config entities is not supported by Drupal's entity API. You tried to filter on a Role config entity.", $response);
}