ProtectedEntityDeleteTest.php in User protect 8
File
tests/src/Kernel/ProtectedEntityDeleteTest.php
View source
<?php
namespace Drupal\Tests\userprotect\Kernel;
class ProtectedEntityDeleteTest extends UserProtectKernelTestBase {
public function testUserDelete() {
$account = $this
->drupalCreateUser();
$protection_rule = $this
->createProtectionRule($account
->id(), [], 'user');
$protection_rule
->save();
$protection_rule = $this
->reloadEntity($protection_rule);
$this
->assertNotNull($protection_rule, 'The protection rule was saved.');
$account
->delete();
$protection_rule = $this
->reloadEntity($protection_rule);
$this
->assertNull($protection_rule, 'The protection rule was deleted.');
}
public function testRoleDelete() {
$rid = $this
->drupalCreateRole([]);
$protection_rule = $this
->createProtectionRule($rid, [], 'user_role');
$protection_rule
->save();
$protection_rule = $this
->reloadEntity($protection_rule);
$this
->assertNotNull($protection_rule, 'The protection rule was saved.');
$role = \Drupal::entityTypeManager()
->getStorage('user_role')
->load($rid);
$role
->delete();
$protection_rule = $this
->reloadEntity($protection_rule);
$this
->assertNull($protection_rule, 'The protection rule was deleted.');
}
}