You are here

public function WorkflowAccessControlHandlerTest::testCheckCreateAccess in Drupal 8

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

@covers ::checkCreateAccess

File

core/modules/workflows/tests/src/Kernel/WorkflowAccessControlHandlerTest.php, line 73

Class

WorkflowAccessControlHandlerTest
@coversDefaultClass \Drupal\workflows\WorkflowAccessControlHandler @group workflows

Namespace

Drupal\Tests\workflows\Kernel

Code

public function testCheckCreateAccess() {

  // A user must have the correct permission to create a workflow.
  $this
    ->assertEquals(AccessResult::neutral()
    ->addCacheContexts([
    'user.permissions',
  ])
    ->setReason("The 'administer workflows' permission is required.")
    ->addCacheTags([
    'workflow_type_plugins',
  ]), $this->accessControlHandler
    ->createAccess(NULL, $this->user, [], TRUE));
  $this
    ->assertEquals(AccessResult::allowed()
    ->addCacheContexts([
    'user.permissions',
  ])
    ->addCacheTags([
    'workflow_type_plugins',
  ]), $this->accessControlHandler
    ->createAccess(NULL, $this->adminUser, [], TRUE));

  // Remove all plugin types and ensure not even the admin user is allowed to
  // create a workflow.
  workflow_type_test_set_definitions([]);
  $this->accessControlHandler
    ->resetCache();
  $this
    ->assertEquals(AccessResult::neutral()
    ->addCacheContexts([
    'user.permissions',
  ])
    ->addCacheTags([
    'workflow_type_plugins',
  ]), $this->accessControlHandler
    ->createAccess(NULL, $this->adminUser, [], TRUE));
}