public function WorkspacePermissionsTest::testEditOwnWorkspace in Workspace 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspace\Functional\WorkspacePermissionsTest::testEditOwnWorkspace()
Verifies that a user can create and edit only their own workspace.
File
- tests/
src/ Functional/ WorkspacePermissionsTest.php, line 66
Class
- WorkspacePermissionsTest
- Tests permission controls on workspaces.
Namespace
Drupal\Tests\workspace\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 = $this
->getOneWorkspaceByLabel('Bears');
$session = $this
->getSession();
$this
->drupalGet("/admin/structure/workspace/{$bears->id()}/edit");
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$page
->fillField('label', 'Bears again');
$page
->fillField('machine_name', 'bears');
$page
->findButton(t('Save'))
->click();
$session
->getPage()
->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);
$session = $this
->getSession();
$this
->createWorkspaceThroughUI('Packers', 'packers');
$packers = $this
->getOneWorkspaceByLabel('Packers');
$this
->drupalGet("/admin/structure/workspace/{$packers->id()}/edit");
$this
->assertEquals(200, $session
->getStatusCode());
$this
->drupalGet("/admin/structure/workspace/{$bears->id()}/edit");
$this
->assertEquals(403, $session
->getStatusCode());
}