function EntityStateChangeValidationTest::testInvalidState
Same name in other branches
- 9 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testInvalidState()
- 8.9.x core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testInvalidState()
- 10 core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php \Drupal\Tests\content_moderation\Kernel\EntityStateChangeValidationTest::testInvalidState()
Tests validation with an invalid state.
File
-
core/
modules/ content_moderation/ tests/ src/ Kernel/ EntityStateChangeValidationTest.php, line 123
Class
- EntityStateChangeValidationTest
- @coversDefaultClass \Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator @group content_moderation
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testInvalidState() : 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 = 'invalid_state';
$violations = $node->validate();
$this->assertCount(1, $violations);
$this->assertEquals('State invalid_state does not exist on Editorial workflow', $violations->get(0)
->getMessage());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.