You are here

public function EntityStateChangeValidationTest::testTransitionAccessValidationSavedEntity in Workbench Moderation 8

Test transition access validation on entity save.

@dataProvider transitionAccessValidationTestCases

File

tests/src/Kernel/EntityStateChangeValidationTest.php, line 219

Class

EntityStateChangeValidationTest
@coversDefaultClass \Drupal\workbench_moderation\Plugin\Validation\Constraint\ModerationStateValidator @group workbench_moderation

Namespace

Drupal\Tests\workbench_moderation\Kernel

Code

public function testTransitionAccessValidationSavedEntity($permissions, $default_state, $target_state, $messages) {
  $this
    ->setCurrentUser($this
    ->createUser($permissions));
  $this
    ->createExampleModeratedContentType($default_state, [
    'draft',
    'needs_review',
    'published',
    'archived',
  ]);
  $node = Node::create([
    'type' => 'example',
    'title' => 'Test content',
    'moderation_state' => $default_state,
  ]);
  $node
    ->save();
  $node->moderation_state = $target_state;
  $violations = $node
    ->validate();
  $this
    ->assertCount(count($messages), $violations);
  foreach ($messages as $i => $message) {
    $this
      ->assertEquals($message, $violations
      ->get($i)
      ->getMessage());
  }
}