public function WorkspacePermissionsTest::testCreateWorkspace in Workspace 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/WorkspacePermissionsTest.php \Drupal\Tests\workspace\Functional\WorkspacePermissionsTest::testCreateWorkspace()
Verifies that a user can create but not edit a workspace.
Throws
\Behat\Mink\Exception\ElementNotFoundException
File
- tests/
src/ Functional/ WorkspacePermissionsTest.php, line 26
Class
- WorkspacePermissionsTest
- Tests permission controls on workspaces.
Namespace
Drupal\Tests\workspace\FunctionalCode
public function testCreateWorkspace() {
$editor = $this
->drupalCreateUser([
'access administration pages',
'administer site configuration',
'create_workspace',
]);
// Login as a limited-access user and create a workspace.
$this
->drupalLogin($editor);
$session = $this
->getSession();
$this
->drupalGet('/admin/structure/workspace/add');
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$page
->fillField('label', 'Bears');
$page
->fillField('machine_name', 'bears');
$page
->findButton(t('Save'))
->click();
$session
->getPage()
->hasContent('Bears (bears)');
// Now edit that same workspace; We shouldn't be able to do so, since
// we don't have edit permissions.
/** @var EntityTypeManagerInterface $etm */
$etm = \Drupal::service('entity_type.manager');
/** @var WorkspaceInterface $bears */
$entity_list = $etm
->getStorage('workspace')
->loadByProperties([
'label' => 'Bears',
]);
$bears = current($entity_list);
$this
->drupalGet("/admin/structure/workspace/{$bears->id()}/edit");
$this
->assertEquals(403, $session
->getStatusCode());
// @todo add Deletion checks once there's a UI for deletion.
}