You are here

public function UserTest::testCollectionContainsAnonymousUser in JSON:API 8.2

Tests that the collection contains the anonymous user.

File

tests/src/Functional/UserTest.php, line 442

Class

UserTest
JSON:API integration test for the "User" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testCollectionContainsAnonymousUser() {
  $url = Url::fromRoute('jsonapi.user--user.collection', [], [
    'query' => [
      'sort' => 'drupal_internal__uid',
    ],
  ]);
  $request_options = [];
  $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
  $request_options = NestedArray::mergeDeep($request_options, $this
    ->getAuthenticationRequestOptions());
  $response = $this
    ->request('GET', $url, $request_options);
  $doc = Json::decode((string) $response
    ->getBody());
  $this
    ->assertCount(4, $doc['data']);
  $this
    ->assertSame(User::load(0)
    ->uuid(), $doc['data'][0]['id']);
  $this
    ->assertSame('Anonymous', $doc['data'][0]['attributes']['name']);
}