You are here

public function ProtectedEntityDeleteTest::testUserDelete in User protect 8

Tests reaction upon user deletion.

Tests if an user based protection rule is cleaned up when the protected user is deleted.

File

tests/src/Kernel/ProtectedEntityDeleteTest.php, line 18

Class

ProtectedEntityDeleteTest
Tests if protection rules are cleaned up upon entity deletion.

Namespace

Drupal\Tests\userprotect\Kernel

Code

public function testUserDelete() {

  // Create a user.
  $account = $this
    ->drupalCreateUser();

  // Protect this user.
  $protection_rule = $this
    ->createProtectionRule($account
    ->id(), [], 'user');
  $protection_rule
    ->save();

  // Assert that the rule was saved.
  $protection_rule = $this
    ->reloadEntity($protection_rule);
  $this
    ->assertNotNull($protection_rule, 'The protection rule was saved.');

  // Now delete the account.
  $account
    ->delete();

  // Assert that the rule no longer exists.
  $protection_rule = $this
    ->reloadEntity($protection_rule);
  $this
    ->assertNull($protection_rule, 'The protection rule was deleted.');
}