You are here

public function WorkspaceAccessTest::testPublishWorkspaceAccess in Drupal 8

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

Tests workspace publishing access.

File

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

Class

WorkspaceAccessTest
Tests access on workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

public function testPublishWorkspaceAccess() {
  $user = $this
    ->createUser([
    'view own workspace',
    'edit own workspace',
  ]);
  $this
    ->setCurrentUser($user);
  $workspace = Workspace::create([
    'id' => 'stage',
  ]);
  $workspace
    ->save();

  // Check that, by default, an admin user is allowed to publish a workspace.
  $workspace
    ->publish();

  // Simulate an external factor which decides that a workspace can not be
  // published.
  \Drupal::state()
    ->set('workspace_access_test.result.publish', AccessResult::forbidden());
  \Drupal::entityTypeManager()
    ->getAccessControlHandler('workspace')
    ->resetCache();
  $this
    ->expectException(WorkspaceAccessException::class);
  $workspace
    ->publish();
}