function ModerationStateWidgetTest::testWidgetNonModeratedEntity

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/ModerationStateWidgetTest.php \Drupal\Tests\content_moderation\Kernel\ModerationStateWidgetTest::testWidgetNonModeratedEntity()
  2. 10 core/modules/content_moderation/tests/src/Kernel/ModerationStateWidgetTest.php \Drupal\Tests\content_moderation\Kernel\ModerationStateWidgetTest::testWidgetNonModeratedEntity()
  3. 11.x 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 <a href="/api/drupal/core%21modules%21content_moderation%21src%21Plugin%21Field%21FieldWidget%21ModerationStateWidget.php/class/ModerationStateWidget/8.9.x" title="Plugin implementation of the &#039;moderation_state_default&#039; widget." class="local">\Drupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget</a> @group content_moderation

Namespace

Drupal\Tests\content_moderation\Kernel

Code

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());
}

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