You are here

public function WorkspacePermissionsTest::testDeleteOwnWorkspace in Workspace 8.2

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

File

tests/src/Functional/WorkspacePermissionsTest.php, line 139

Class

WorkspacePermissionsTest
Tests permission controls on workspaces.

Namespace

Drupal\Tests\workspace\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/workspace/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/workspace/manage/{$packers->id()}/delete");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->drupalGet("/admin/config/workflow/workspace/manage/{$bears->id()}/delete");
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}