You are here

public function WorkspaceViewTest::testViewOwnWorkspace in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/workspaces/tests/src/Functional/WorkspaceViewTest.php \Drupal\Tests\workspaces\Functional\WorkspaceViewTest::testViewOwnWorkspace()

Verifies that a user can view their own workspace.

File

core/modules/workspaces/tests/src/Functional/WorkspaceViewTest.php, line 30

Class

WorkspaceViewTest
Tests permission controls on workspaces.

Namespace

Drupal\Tests\workspaces\Functional

Code

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

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

  // Now login as a different user and create a workspace.
  $editor2 = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($editor2);
  $this
    ->createWorkspaceThroughUi('Packers', 'packers');
  $packers = Workspace::load('packers');

  // Load the activate form for the Bears workspace. It should fail because
  // the workspace belongs to someone else.
  $this
    ->drupalGet("admin/config/workflow/workspaces/manage/{$bears->id()}/activate");
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // But editor 2 should be able to activate the Packers workspace.
  $this
    ->drupalGet("admin/config/workflow/workspaces/manage/{$packers->id()}/activate");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}