/** @var \Drupal\user\UserInterface $user */
$user =
static::
$auth ?
$this->account : User::
load(0
);
// @todo Remove the array_diff_key() call in https://www.drupal.org/node/2821077.
$original_normalization =
array_diff_key($this->serializer->
normalize($user,
static::
$format),
['created' => TRUE, 'changed' => TRUE, 'name' => TRUE
]);
// Since this test must be performed by the user that is being modified,
// we cannot use $this->getUrl().
$url =
$user->
toUrl()->
setOption('query',
['_format' =>
static::
$format]);
$request_options =
[ RequestOptions::HEADERS =>
['Content-Type' =>
static::
$mimeType],
];
$request_options =
array_merge_recursive($request_options,
$this->
getAuthenticationRequestOptions('PATCH'
));
// Test case 1: changing email.
$normalization =
$original_normalization;
$normalization['mail'
] =
[['value' => 'new-email@example.com'
]];
$request_options[RequestOptions::BODY
] =
$this->serializer->
encode($normalization,
static::
$format);
// DX: 422 when changing email without providing the password.
$response =
$this->
request('PATCH',
$url,
$request_options);
$this->
assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\nmail: Your current password is missing or incorrect; it's required to change the Email.\n",
$response, FALSE, FALSE, FALSE, FALSE
);
$normalization['pass'
] =
[['existing' => 'wrong'
]];