You are here

public function EntityStateChangeValidationTest::testExistingContentWithNoModeration in Drupal 8

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

Tests that content without prior moderation information can be moderated.

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testExistingContentWithNoModeration() {
  $this
    ->setCurrentUser($this->adminUser);
  $node_type = NodeType::create([
    'type' => 'example',
  ]);
  $node_type
    ->save();

  /** @var \Drupal\node\NodeInterface $node */
  $node = Node::create([
    'type' => 'example',
    'title' => 'Test title',
  ]);
  $node
    ->save();
  $nid = $node
    ->id();

  // Enable moderation for our node type.
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('node', 'example');
  $workflow
    ->save();
  $node = Node::load($nid);

  // Having no previous state should not break validation.
  $violations = $node
    ->validate();
  $this
    ->assertCount(0, $violations);

  // Having no previous state should not break saving the node.
  $node
    ->setTitle('New');
  $node
    ->save();
}