function WorkflowAccessControlHandlerTest::testCheckCreateAccess

Tests check create access.

@legacy-covers ::checkCreateAccess

File

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

Class

WorkflowAccessControlHandlerTest
Tests Drupal\workflows\WorkflowAccessControlHandler.

Namespace

Drupal\Tests\workflows\Kernel

Code

public function testCheckCreateAccess() : void {
  // 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."), $this->accessControlHandler
    ->createAccess(NULL, $this->user, [], TRUE));
  $this->assertEquals(AccessResult::allowed()->addCacheContexts([
    'user.permissions',
  ]), $this->accessControlHandler
    ->createAccess(NULL, $this->adminUser, [], TRUE));
  // Remove all plugin types and ensure not even the admin user is allowed to
  // create a workflow.
  $this->container
    ->get('state')
    ->set('workflow_type_test.plugin_definitions', []);
  $this->container
    ->get('plugin.manager.workflows.type')
    ->clearCachedDefinitions();
  $this->accessControlHandler
    ->resetCache();
  $this->assertEquals(AccessResult::neutral()->addCacheContexts([
    'user.permissions',
  ]), $this->accessControlHandler
    ->createAccess(NULL, $this->adminUser, [], TRUE));
}

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