function WorkspaceAccessTest::testWorkspaceAccess

Same name and namespace in other branches
  1. 9 core/modules/workspaces/tests/src/Kernel/WorkspaceAccessTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceAccessTest::testWorkspaceAccess()
  2. 10 core/modules/workspaces/tests/src/Kernel/WorkspaceAccessTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceAccessTest::testWorkspaceAccess()
  3. 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceAccessTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceAccessTest::testWorkspaceAccess()

Verifies all workspace roles have the correct access for the operation.

@dataProvider operationCases

Parameters

string $operation: The operation to test with.

string $permission: The permission to test with.

File

core/modules/workspaces/tests/src/Kernel/WorkspaceAccessTest.php, line 75

Class

WorkspaceAccessTest
Tests access on workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

public function testWorkspaceAccess($operation, $permission) {
    $user = $this->createUser();
    $this->setCurrentUser($user);
    $workspace = Workspace::create([
        'id' => 'oak',
    ]);
    $workspace->save();
    $this->assertFalse($workspace->access($operation, $user));
    \Drupal::entityTypeManager()->getAccessControlHandler('workspace')
        ->resetCache();
    $role = $this->createRole([
        $permission,
    ]);
    $user->addRole($role);
    $this->assertTrue($workspace->access($operation, $user));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.