You are here

public function DeleteUserTest::testUserDelete in Workbench Access 8

Tests that deleting a user clears their data from storage.

File

tests/src/Functional/DeleteUserTest.php, line 42

Class

DeleteUserTest
Tests for deleting a user and removing associated data.

Namespace

Drupal\Tests\workbench_access\Functional

Code

public function testUserDelete() {

  // Add page content type.
  $this
    ->setUpContentType();

  // Set up a content type and menu scheme.
  $scheme = $this
    ->setUpMenuScheme([
    'page',
  ], [
    'main',
  ]);
  $user_storage = $this->container
    ->get('workbench_access.user_section_storage');

  // Set up an editor.
  $editor = $this
    ->setUpEditorUser();

  // Set up a second editor.
  $admin = $this
    ->setUpAdminUser([
    'create page content',
    'edit any page content',
    'administer menu',
    'delete any page content',
    'use workbench access',
  ]);

  // Set up a menu link for this test.
  $base_link = MenuLinkContent::create([
    'title' => 'Link 1',
    'link' => [
      [
        'uri' => 'route:<front>',
      ],
    ],
    'menu_name' => 'main',
  ]);
  $base_link
    ->save();

  // Add the first user to the base section.
  $user_storage
    ->addUser($scheme, $editor, [
    $base_link
      ->getPluginId(),
  ]);

  // Add the second user to the base section.
  $user_storage
    ->addUser($scheme, $admin, [
    $base_link
      ->getPluginId(),
  ]);

  // Get assigned users.
  $existing_users = $user_storage
    ->getEditors($scheme, $base_link
    ->getPluginId());

  // Assert that these are the same.
  $this
    ->assertEquals([
    $editor
      ->id(),
    $admin
      ->id(),
  ], array_keys($existing_users));

  // Delete the first user.
  $editor
    ->delete();

  // Get assigned users.
  $existing_users = $user_storage
    ->getEditors($scheme, $base_link
    ->getPluginId());

  // Assert that these are the same.
  $this
    ->assertEquals([
    $admin
      ->id(),
  ], array_keys($existing_users));
}