You are here

public function EntityStateChangeValidationTest::testInvalidTransition in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testInvalidTransition()
  2. 10 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testInvalidTransition()

Tests invalid transitions.

@covers ::validate

File

core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php, line 92

Class

EntityStateChangeValidationTest
@coversDefaultClass \Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator @group content_moderation

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testInvalidTransition() {
  $this
    ->setCurrentUser($this->adminUser);
  $node_type = NodeType::create([
    'type' => 'example',
  ]);
  $node_type
    ->save();
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('node', 'example');
  $workflow
    ->save();
  $node = Node::create([
    'type' => 'example',
    'title' => 'Test title',
  ]);
  $node->moderation_state->value = 'draft';
  $node
    ->save();
  $node->moderation_state->value = 'archived';
  $violations = $node
    ->validate();
  $this
    ->assertCount(1, $violations);
  $this
    ->assertEquals('Invalid state transition from <em class="placeholder">Draft</em> to <em class="placeholder">Archived</em>', $violations
    ->get(0)
    ->getMessage());
}