public function ModerationStateWidgetTest::testWidgetNonModeratedEntity in Drupal 8
Same name and namespace in other branches
- 9 core/modules/content_moderation/tests/src/Kernel/ModerationStateWidgetTest.php \Drupal\Tests\content_moderation\Kernel\ModerationStateWidgetTest::testWidgetNonModeratedEntity()
Test the widget does not impact a non-moderated entity.
File
- core/
modules/ content_moderation/ tests/ src/ Kernel/ ModerationStateWidgetTest.php, line 59
Class
- ModerationStateWidgetTest
- @coversDefaultClass \Drupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget @group content_moderation
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testWidgetNonModeratedEntity() {
// Create an unmoderated entity and build a form display which will include
// the ModerationStateWidget plugin, in a hidden state.
$entity = Node::create([
'type' => 'unmoderated',
]);
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'unmoderated',
'mode' => 'default',
'status' => TRUE,
]);
$form = [];
$form_state = new FormState();
$entity_form_display
->buildForm($entity, $form, $form_state);
// The moderation_state field should have no values for an entity that isn't
// being moderated.
$entity_form_display
->extractFormValues($entity, $form, $form_state);
$this
->assertEquals(0, $entity->moderation_state
->count());
}