You are here

public function WorkspacePermissionsTest::testDeleteOwnWorkspace 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::testDeleteOwnWorkspace()
  2. 10 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testDeleteOwnWorkspace()

Verifies that a user can create and delete only their own workspace.

File

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

Class

WorkspacePermissionsTest
Tests permission controls on workspaces.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testDeleteOwnWorkspace() {
  $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 try to delete 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 don't have edit access,
  // and vice versa.
  $editor2 = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($editor2);
  $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(403);
}