function ModerationStateWidgetTest::testWidgetNonModeratedEntity
Tests the widget does not impact a non-moderated entity.
File
- 
              core/
modules/ content_moderation/ tests/ src/ Kernel/ ModerationStateWidgetTest.php, line 61  
Class
- ModerationStateWidgetTest
 - @coversDefaultClass \Drupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget[[api-linebreak]] @group content_moderation
 
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testWidgetNonModeratedEntity() : void {
  // 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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.