You are here

public function WorkspacePermissionsTest::testCreateWorkspace in Drupal 10

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

Verifies that a user can create but not edit a workspace.

File

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

Class

WorkspacePermissionsTest
Tests permission controls on workspaces.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testCreateWorkspace() {
  $editor = $this
    ->drupalCreateUser([
    'access administration pages',
    'administer site configuration',
    'create workspace',
  ]);

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

  // Now edit that same workspace; We shouldn't be able to do so, since
  // we don't have edit permissions.

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $etm */
  $etm = \Drupal::service('entity_type.manager');

  /** @var \Drupal\workspaces\WorkspaceInterface $bears */
  $entity_list = $etm
    ->getStorage('workspace')
    ->loadByProperties([
    'label' => 'Bears',
  ]);
  $bears = current($entity_list);
  $this
    ->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/edit");
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}