WorkspaceIndividualPermissionsTest.php in Workspace 8
File
tests/src/Functional/WorkspaceIndividualPermissionsTest.php
View source
<?php
namespace Drupal\Tests\workspace\Functional;
use Drupal\Tests\BrowserTestBase;
class WorkspaceIndividualPermissionsTest extends BrowserTestBase {
use WorkspaceTestUtilities;
public static $modules = [
'workspace',
'multiversion',
];
public function testEditIndividualWorkspace() {
$permissions = [
'access administration pages',
'administer site configuration',
'create_workspace',
'edit_own_workspace',
'view_own_workspace',
];
$editor1 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($editor1);
$this
->createWorkspaceThroughUI('Bears', 'bears');
$bears = $this
->getOneWorkspaceByLabel('Bears');
$editor2 = $this
->drupalCreateUser(array_merge($permissions, [
'update_workspace_' . $bears
->id(),
]));
$this
->drupalLogin($editor2);
$session = $this
->getSession();
$this
->drupalGet("/admin/structure/workspace/{$bears->id()}/edit");
$this
->assertEquals(200, $session
->getStatusCode());
}
public function testViewIndividualWorkspace() {
$permissions = [
'access administration pages',
'administer site configuration',
'create_workspace',
'edit_own_workspace',
];
$editor1 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($editor1);
$this
->createWorkspaceThroughUI('Bears', 'bears');
$bears = $this
->getOneWorkspaceByLabel('Bears');
$editor2 = $this
->drupalCreateUser(array_merge($permissions, [
'view_workspace_' . $bears
->id(),
]));
$this
->drupalLogin($editor2);
$session = $this
->getSession();
$this
->createWorkspaceThroughUI('Packers', 'packers');
$packers = $this
->getOneWorkspaceByLabel('Packers');
$this
->drupalGet("admin/structure/workspace/{$bears->id()}/activate");
$this
->assertEquals(200, $session
->getStatusCode());
$this
->drupalLogin($editor1);
$this
->drupalGet("admin/structure/workspace/{$packers->id()}/activate");
$this
->assertEquals(403, $session
->getStatusCode());
}
}