function UserTest::testCollectionContainsAnonymousUser

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testCollectionContainsAnonymousUser()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testCollectionContainsAnonymousUser()
  3. 10 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testCollectionContainsAnonymousUser()

Tests that the collection contains the anonymous user.

File

core/modules/jsonapi/tests/src/Functional/UserTest.php, line 482

Class

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

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testCollectionContainsAnonymousUser() : void {
    $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 = $this->getDocumentFromResponse($response);
    $this->assertCount(4, $doc['data']);
    $this->assertSame(User::load(0)->uuid(), $doc['data'][0]['id']);
    $this->assertSame('User 0', $doc['data'][0]['attributes']['display_name']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.