function EntityStateChangeValidationTest::testExistingContentWithNoModeration

Same name and namespace in other branches
  1. 8.9.x core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testExistingContentWithNoModeration()
  2. 10 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 249

Class

EntityStateChangeValidationTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21content_moderation%21src%21Plugin%21Validation%21Constraint%21ModerationStateConstraintValidator.php/class/ModerationStateConstraintValidator/9" title="Checks if a moderation state transition is valid." class="local">\Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator</a> @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();
}

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