public function WorkspacePermissionsTest::testEditOwnWorkspace in Drupal 9
Same name and namespace in other branches
- 8 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 56
Class
- WorkspacePermissionsTest
- Tests permission controls on workspaces.
Namespace
Drupal\Tests\workspaces\FunctionalCode
public function testEditOwnWorkspace() {
$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);
}