function WorkspacePermissionsTest::testEditAnyWorkspace

Same name in other branches
  1. 9 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testEditAnyWorkspace()
  2. 8.9.x core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testEditAnyWorkspace()
  3. 10 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testEditAnyWorkspace()

Verifies that a user can edit any workspace.

File

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

Class

WorkspacePermissionsTest
Tests permission controls on workspaces.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testEditAnyWorkspace() : void {
    $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 = Workspace::load('bears');
    $this->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/edit");
    $this->assertSession()
        ->statusCodeEquals(200);
    $page = $this->getSession()
        ->getPage();
    $page->fillField('label', 'Bears again');
    $page->fillField('id', 'bears');
    $page->findButton('Save')
        ->click();
    $page->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);
    $this->createWorkspaceThroughUi('Packers', 'packers');
    $packers = Workspace::load('packers');
    $this->drupalGet("/admin/config/workflow/workspaces/manage/{$packers->id()}/edit");
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/edit");
    $this->assertSession()
        ->statusCodeEquals(200);
}

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