You are here

public function WorkflowsFieldContraintTest::testInvalidTransition in Workflows Field 2.x

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

Test we can not apply invalid transitions.

File

tests/src/Kernel/WorkflowsFieldContraintTest.php, line 45

Class

WorkflowsFieldContraintTest
Tests the field constraints.

Namespace

Drupal\Tests\workflows_field\Kernel

Code

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

  // Violation exists during invalid transition.
  $node->field_status->value = 'planning';
  $violations = $node
    ->validate();
  $this
    ->assertCount(1, $violations);
  $this
    ->assertEquals('No transition exists to move from <em class="placeholder">in_discussion</em> to <em class="placeholder">planning</em>.', $violations[0]
    ->getMessage());
}