public function DeleteRoleTest::testRoleDelete in Workbench Access 8
Tests that deleting a role clears their data from storage.
File
- tests/
src/ Functional/ DeleteRoleTest.php, line 43
Class
- DeleteRoleTest
- Tests for deleting a role and removing associated data.
Namespace
Drupal\Tests\workbench_access\FunctionalCode
public function testRoleDelete() {
$this
->setUpContentType();
$scheme = $this
->setUpMenuScheme([
'page',
], [
'main',
]);
$base_link = MenuLinkContent::create([
'title' => 'Link 1',
'link' => [
[
'uri' => 'route:<front>',
],
],
'menu_name' => 'main',
]);
$base_link
->save();
$section_id = $base_link
->getPluginId();
$this
->setUpRole('role_a');
$this
->setUpRole('role_b');
/* @var \Drupal\workbench_access\RoleSectionStorageInterface $role_section_storage */
$role_section_storage = $this->container
->get('workbench_access.role_section_storage');
$role_section_storage
->addRole($scheme, 'role_a', [
$section_id,
]);
$role_section_storage
->addRole($scheme, 'role_b', [
$section_id,
]);
$assigned_roles = $this
->getStoredRoles($scheme, $section_id);
$this
->assertCount(2, $assigned_roles, 'The test roles are not assigned to the section.');
/* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $this->container
->get('entity_type.manager');
$role_storage = $entity_type_manager
->getStorage('user_role');
$role_b = $role_storage
->load('role_b');
$role_b
->delete();
$assigned_roles = $this
->getStoredRoles($scheme, $section_id);
$this
->assertCount(1, $assigned_roles, 'The test roles are not assigned to the section.');
}