You are here

public function EntityStateChangeValidationTest::testContent in Workbench Moderation 8

Verifies if content without prior moderation information can be moderated.

File

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

Class

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

Namespace

Drupal\Tests\workbench_moderation\Kernel

Code

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

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

  // Enable moderation for our node type.

  /** @var \Drupal\node\Entity\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();
}