function UserTest::testDeleteRespectsUserCancelReassign

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testDeleteRespectsUserCancelReassign()
  2. 10 core/modules/jsonapi/tests/src/Functional/UserTest.php \Drupal\Tests\jsonapi\Functional\UserTest::testDeleteRespectsUserCancelReassign()

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

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testDeleteRespectsUserCancelReassign() : void {
    $cancel_method = 'user_cancel_reassign';
    $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(),
    ]);
    $this->sendDeleteRequestForUser($account, $cancel_method);
    $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 = $this->container
        ->get('entity_type.manager')
        ->getStorage('node');
    $node_storage->resetCache([
        $node->id(),
    ]);
    $test_node = $node_storage->load($node->id());
    $this->assertNotNull($test_node, 'Node of the user is not deleted.');
    $this->assertTrue($test_node->isPublished(), 'Node of the user is still published.');
    $this->assertEquals(0, $test_node->getOwnerId(), 'Node of the user has been attributed to anonymous user.');
    $test_node = $node_storage->loadRevision($node->getRevisionId());
    $this->assertTrue($test_node->isPublished(), 'Node revision of the user is still published.');
    $this->assertEquals(0, $test_node->getRevisionUser()
        ->id(), 'Node revision of the user has been attributed to anonymous user.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.