function WorkspacePermissionsTest::testEditOwnWorkspace
Same name in other branches
- 9 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testEditOwnWorkspace()
- 8.9.x core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testEditOwnWorkspace()
- 10 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testEditOwnWorkspace()
Verifies that a user can create and edit only their own workspace.
File
-
core/
modules/ workspaces/ tests/ src/ Functional/ WorkspacePermissionsTest.php, line 58
Class
- WorkspacePermissionsTest
- Tests permission controls on workspaces.
Namespace
Drupal\Tests\workspaces\FunctionalCode
public function testEditOwnWorkspace() : 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.
$editor2 = $this->drupalCreateUser($permissions);
$this->drupalLogin($editor2);
$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(403);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.