public function JsonapiResourceTest::testCurrentUserInfoResource in JSON:API Resources 8
Tests the Current User Info resource.
File
- tests/
src/ Functional/ JsonapiResourceTest.php, line 249
Class
- JsonapiResourceTest
- Tests JSON:API Resource processors.
Namespace
Drupal\Tests\jsonapi_resources\FunctionalCode
public function testCurrentUserInfoResource() {
$role_id = $this
->drupalCreateRole([]);
$this->account
->addRole($role_id);
$this->account
->setEmail('test@example.com');
$this->account
->save();
$url = Url::fromUri('internal:/jsonapi/me');
$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);
$this
->assertSame(200, $response
->getStatusCode(), var_export(Json::decode((string) $response
->getBody()), TRUE));
$response_document = Json::decode((string) $response
->getBody());
$this
->assertEquals($this->account
->uuid(), $response_document['data']['id']);
$attributes = $response_document['data']['attributes'];
$this
->assertEquals($this->account
->getDisplayName(), $attributes['displayName']);
$this
->assertEquals([
$role_id,
], $attributes['roles']);
$this
->assertNotEmpty($attributes['token']);
}