function UserTest::testResaveAccountName
Same name in other branches
- 8.9.x core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testResaveAccountName()
- 10 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testResaveAccountName()
- 11.x core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testResaveAccountName()
Tests users with altered display names.
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ UserTest.php, line 589
Class
- UserTest
- JSON:API integration test for the "User" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testResaveAccountName() {
$this->config('jsonapi.settings')
->set('read_only', FALSE)
->save(TRUE);
$this->setUpAuthorization('PATCH');
$original_name = $this->entity
->get('name')->value;
$url = Url::fromRoute('jsonapi.user--user.individual', [
'entity' => $this->entity
->uuid(),
]);
$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);
// Send the unchanged data back.
$request_options[RequestOptions::BODY] = (string) $response->getBody();
$request_options[RequestOptions::HEADERS]['Content-Type'] = 'application/vnd.api+json';
$response = $this->request('PATCH', $url, $request_options);
$this->assertEquals(200, $response->getStatusCode());
// Load the user entity again, make sure the name was not changed.
$this->entityStorage
->resetCache();
$updated_user = $this->entityStorage
->load($this->entity
->id());
$this->assertEquals($original_name, $updated_user->get('name')->value);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.