You are here

public function EntityStateChangeValidationTest::testLegacyContent in Workbench Moderation 8.2

Verifies that content without prior moderation information can be moderated.

File

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

Class

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

Namespace

Drupal\Tests\workbench_moderation\Kernel

Code

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

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

  // Enable moderation for our node type.

  /** @var NodeType $node_type */
  $node_type = NodeType::load('example');
  $node_type
    ->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
  $node_type
    ->setThirdPartySetting('workbench_moderation', 'allowed_moderation_states', [
    'draft',
    'needs_review',
    'published',
  ]);
  $node_type
    ->setThirdPartySetting('workbench_moderation', 'default_moderation_state', 'draft');
  $node_type
    ->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();
}