public function EntityStateChangeValidationTest::testInvalidTransition in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\workbench_moderation\Kernel\EntityStateChangeValidationTest::testInvalidTransition()
Test invalid transitions.
@covers ::validate
File
- tests/
src/ Kernel/ EntityStateChangeValidationTest.php, line 81
Class
- EntityStateChangeValidationTest
- @coversDefaultClass \Drupal\workbench_moderation\Plugin\Validation\Constraint\ModerationStateValidator @group workbench_moderation
Namespace
Drupal\Tests\workbench_moderation\KernelCode
public function testInvalidTransition() {
$this
->setCurrentUser($this->adminUser);
$node_type = NodeType::create([
'type' => 'example',
]);
$node_type
->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
$node_type
->save();
$node = Node::create([
'type' => 'example',
'title' => 'Test title',
'moderation_state' => 'draft',
]);
$node
->save();
$node->moderation_state->target_id = 'archived';
$violations = $node
->validate();
$this
->assertCount(1, $violations);
$this
->assertEquals('Invalid state transition from <em class="placeholder">Draft</em> to <em class="placeholder">Archived</em>', $violations
->get(0)
->getMessage());
}