function EntityStateChangeValidationTest::testValidTransition

Same name in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testValidTransition()
  2. 8.9.x core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testValidTransition()
  3. 10 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testValidTransition()

Tests valid transitions.

@covers ::validate

File

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

Class

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

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testValidTransition() : void {
    $node_type = NodeType::create([
        'type' => 'example',
        'name' => 'Example',
    ]);
    $node_type->save();
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()
        ->addEntityTypeAndBundle('node', 'example');
    $workflow->save();
    $node = Node::create([
        'type' => 'example',
        'title' => 'Test title',
    ]);
    $node->moderation_state->value = 'draft';
    $node->save();
    $this->setCurrentUser($this->createUser([
        'use editorial transition publish',
    ]));
    $node->moderation_state->value = 'published';
    $this->assertCount(0, $node->validate());
    $node->save();
    $this->assertEquals('published', $node->moderation_state->value);
}

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