You are here

public function WorkflowsFormatterTest::testStatesListFormatter in Workflows Field 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/WorkflowsFormatterTest.php \Drupal\Tests\workflows_field\Kernel\WorkflowsFormatterTest::testStatesListFormatter()

Test the states list formatter.

File

tests/src/Kernel/WorkflowsFormatterTest.php, line 18

Class

WorkflowsFormatterTest
Tests the Workflows Field formatters.

Namespace

Drupal\Tests\workflows_field\Kernel

Code

public function testStatesListFormatter() {
  $node = Node::create([
    'title' => 'Foo',
    'type' => 'project',
    'field_status' => 'in_discussion',
  ]);
  $node
    ->save();
  $output = $node->field_status
    ->view([
    'type' => 'workflows_field_state_list',
  ]);
  $this
    ->assertEquals([
    [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => 'Implementing',
      '#wrapper_attributes' => [
        'class' => [
          'implementing',
          'before-current',
        ],
      ],
    ],
    [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => 'Approved',
      '#wrapper_attributes' => [
        'class' => [
          'approved',
          'before-current',
        ],
      ],
    ],
    [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => 'Rejected',
      '#wrapper_attributes' => [
        'class' => [
          'rejected',
          'before-current',
        ],
      ],
    ],
    [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => 'Planning',
      '#wrapper_attributes' => [
        'class' => [
          'planning',
          'before-current',
        ],
      ],
    ],
    [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => 'In Discussion',
      '#wrapper_attributes' => [
        'class' => [
          'in_discussion',
          'is-current',
        ],
      ],
    ],
  ], $output[0]['#items']);

  // Try with settings excluded.
  $output = $node->field_status
    ->view([
    'type' => 'workflows_field_state_list',
    'settings' => [
      'excluded_states' => [
        'in_discussion' => 'in_discussion',
        'planning' => 'planning',
        'rejected' => 'rejected',
        'approved' => 'approved',
      ],
    ],
  ]);
  $this
    ->assertEquals([
    [
      '#type' => 'html_tag',
      '#tag' => 'span',
      '#value' => 'Implementing',
      '#wrapper_attributes' => [
        'class' => [
          'implementing',
          'before-current',
        ],
      ],
    ],
  ], $output[0]['#items']);
}