public function UserTest::testResaveAccountName in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testResaveAccountName()
- 9 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);
}