You are here

public function WorkspacePermissionsTest::testDeleteAnyWorkspace in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testDeleteAnyWorkspace()
  2. 10 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testDeleteAnyWorkspace()

Verifies that a user can delete any workspace.

File

core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php, line 178

Class

WorkspacePermissionsTest
Tests permission controls on workspaces.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testDeleteAnyWorkspace() {
  $permissions = [
    'access administration pages',
    'administer site configuration',
    'create workspace',
    'delete own workspace',
  ];
  $editor1 = $this
    ->drupalCreateUser($permissions);

  // Login as a limited-access user and create a workspace.
  $this
    ->drupalLogin($editor1);
  $bears = $this
    ->createWorkspaceThroughUi('Bears', 'bears');

  // Now edit that same workspace; We should be able to do so.
  $this
    ->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/delete");
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Now login as a different user and ensure they have delete access on both
  // workspaces.
  $admin = $this
    ->drupalCreateUser(array_merge($permissions, [
    'delete any workspace',
  ]));
  $this
    ->drupalLogin($admin);
  $packers = $this
    ->createWorkspaceThroughUi('Packers', 'packers');
  $this
    ->drupalGet("/admin/config/workflow/workspaces/manage/{$packers->id()}/delete");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/delete");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}