You are here

public function UserTest::testDeleteRespectsUserCancelDelete in Drupal 10

Tests if JSON:API respects user.settings.cancel_method: user_cancel_delete.

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testDeleteRespectsUserCancelDelete() {
  $cancel_method = 'user_cancel_delete';
  $this
    ->config('jsonapi.settings')
    ->set('read_only', FALSE)
    ->save(TRUE);
  $this
    ->config('user.settings')
    ->set('cancel_method', $cancel_method)
    ->save(TRUE);
  $account = $this
    ->createAnotherEntity($cancel_method);
  $node = $this
    ->drupalCreateNode([
    'uid' => $account
      ->id(),
  ]);
  $url = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName), [
    'entity' => $account
      ->uuid(),
  ]);
  $request_options = [];
  $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
  $request_options = NestedArray::mergeDeep($request_options, $this
    ->getAuthenticationRequestOptions());
  $this
    ->setUpAuthorization('DELETE');
  $response = $this
    ->request('DELETE', $url, $request_options);
  $this
    ->assertResourceResponse(204, NULL, $response);
  $node_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('node');
  $user_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('user');
  $user_storage
    ->resetCache([
    $account
      ->id(),
  ]);
  $account = $user_storage
    ->load($account
    ->id());
  $this
    ->assertNull($account, 'User is deleted after JSON:API DELETE operation with user.settings.cancel_method: ' . $cancel_method);
  $node_storage
    ->resetCache([
    $node
      ->id(),
  ]);
  $test_node = $node_storage
    ->load($node
    ->id());
  $this
    ->assertNull($test_node, 'Node of the user is deleted.');
}