You are here

public function WorkspacePermissionsTest::testEditAnyWorkspace in Workspace 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspace\Functional\WorkspacePermissionsTest::testEditAnyWorkspace()

Verifies that a user can edit any workspace.

File

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

Class

WorkspacePermissionsTest
Tests permission controls on workspaces.

Namespace

Drupal\Tests\workspace\Functional

Code

public function testEditAnyWorkspace() {
  $permissions = [
    'access administration pages',
    'administer site configuration',
    'create_workspace',
    'edit_own_workspace',
  ];
  $editor1 = $this
    ->drupalCreateUser($permissions);

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

  // Now edit that same workspace; We should be able to do so.
  $bears = $this
    ->getOneWorkspaceByLabel('Bears');
  $session = $this
    ->getSession();
  $this
    ->drupalGet("/admin/structure/workspace/{$bears->id()}/edit");
  $this
    ->assertEquals(200, $session
    ->getStatusCode());
  $page = $session
    ->getPage();
  $page
    ->fillField('label', 'Bears again');
  $page
    ->fillField('machine_name', 'bears');
  $page
    ->findButton(t('Save'))
    ->click();
  $session
    ->getPage()
    ->hasContent('Bears again (bears)');

  // Now login as a different user and ensure they don't have edit access,
  // and vice versa.
  $admin = $this
    ->drupalCreateUser(array_merge($permissions, [
    'edit_any_workspace',
  ]));
  $this
    ->drupalLogin($admin);
  $session = $this
    ->getSession();
  $this
    ->createWorkspaceThroughUI('Packers', 'packers');
  $packers = $this
    ->getOneWorkspaceByLabel('Packers');
  $this
    ->drupalGet("/admin/structure/workspace/{$packers->id()}/edit");
  $this
    ->assertEquals(200, $session
    ->getStatusCode());
  $this
    ->drupalGet("/admin/structure/workspace/{$bears->id()}/edit");
  $this
    ->assertEquals(200, $session
    ->getStatusCode());
}