function EntityStateChangeValidationTest::testExistingContentWithNoModeration

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()
  2. 8.9.x core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testExistingContentWithNoModeration()
  3. 11.x 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 263

Class

EntityStateChangeValidationTest
@coversDefaultClass \Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator[[api-linebreak]] @group content_moderation

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testExistingContentWithNoModeration() : void {
  $this->setCurrentUser($this->adminUser);
  $node_type = NodeType::create([
    'type' => 'example',
    'name' => '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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.