You are here

public function WorkflowsFieldTest::testOptionsProviderFilteredByUser in Workflows Field 2.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/WorkflowsFieldTest.php \Drupal\Tests\workflows_field\Kernel\WorkflowsFieldTest::testOptionsProviderFilteredByUser()

Settable options are filtered by the users permissions.

File

tests/src/Kernel/WorkflowsFieldTest.php, line 57

Class

WorkflowsFieldTest
Test the workflows field.

Namespace

Drupal\Tests\workflows_field\Kernel

Code

public function testOptionsProviderFilteredByUser() {
  $node = Node::create([
    'title' => 'Foo',
    'type' => 'project',
    'field_status' => 'in_discussion',
  ]);
  $node
    ->save();

  // If a user has no permissions then the only available state is the current
  // state.
  $this
    ->assertEquals([
    'in_discussion' => 'In Discussion',
  ], $node->field_status[0]
    ->getSettableOptions($this
    ->createUser()));

  // Grant the ability to use the approved_project transition and the user
  // should now be able to set the Approved state.
  $this
    ->assertEquals([
    'in_discussion' => 'In Discussion',
    'approved' => 'Approved',
  ], $node->field_status[0]
    ->getSettableOptions($this
    ->createUser([
    'use bureaucracy_workflow transition approved_project',
  ])));
}