function WorkspacePermissionsTest::testCreateWorkspace

Same name in other branches
  1. 9 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testCreateWorkspace()
  2. 10 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testCreateWorkspace()
  3. 11.x 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.