public function WorkspacePermissionsTest::testEditAnyWorkspace in Drupal 9
Same name and namespace in other branches
- 8 core/modules/workspaces/tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspaces\Functional\WorkspacePermissionsTest::testEditAnyWorkspace()
- 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 100
Class
- WorkspacePermissionsTest
- Tests permission controls on workspaces.
Namespace
Drupal\Tests\workspaces\FunctionalCode
public function testEditAnyWorkspace() {
$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);
}