3 namespace Drupal\Tests\workspaces\Kernel;
5 use Drupal\KernelTests\KernelTestBase;
6 use Drupal\Tests\user\Traits\UserCreationTrait;
7 use Drupal\workspaces\Entity\Workspace;
10 * Tests access on workspaces.
14 class WorkspaceAccessTest extends KernelTestBase {
16 use UserCreationTrait;
21 protected static $modules = [
30 protected function setUp() {
33 $this->installSchema('system', ['sequences']);
35 $this->installEntitySchema('workspace');
36 $this->installEntitySchema('workspace_association');
37 $this->installEntitySchema('user');
44 * Test cases for testWorkspaceAccess().
47 * An array of operations and permissions to test with.
49 public function operationCases() {
51 ['create', 'create workspace'],
52 ['view', 'view any workspace'],
53 ['view', 'view own workspace'],
54 ['update', 'edit any workspace'],
55 ['update', 'edit own workspace'],
56 ['delete', 'delete any workspace'],
57 ['delete', 'delete own workspace'],
62 * Verifies all workspace roles have the correct access for the operation.
64 * @param string $operation
65 * The operation to test with.
66 * @param string $permission
67 * The permission to test with.
69 * @dataProvider operationCases
71 public function testWorkspaceAccess($operation, $permission) {
72 $user = $this->createUser();
73 $this->setCurrentUser($user);
74 $workspace = Workspace::create(['id' => 'oak']);
77 $this->assertFalse($workspace->access($operation, $user));
79 \Drupal::entityTypeManager()->getAccessControlHandler('workspace')->resetCache();
80 $role = $this->createRole([$permission]);
81 $user->addRole($role);
82 $this->assertTrue($workspace->access($operation, $user));