You are here

public function DateTimeFormInjectionTest::testDatetimeSerialization in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/datetime/tests/src/Kernel/DateTimeFormInjectionTest.php \Drupal\Tests\datetime\Kernel\DateTimeFormInjectionTest::testDatetimeSerialization()

Tests custom string injection serialization.

File

core/modules/datetime/tests/src/Kernel/DateTimeFormInjectionTest.php, line 102

Class

DateTimeFormInjectionTest
Tests serializing a form with an injected datetime instance.

Namespace

Drupal\Tests\datetime\Kernel

Code

public function testDatetimeSerialization() {
  $form_state = new FormState();
  $form_state
    ->setRequestMethod('POST');
  $form_state
    ->setCached();
  $form_builder = $this->container
    ->get('form_builder');
  $form_id = $form_builder
    ->getFormId($this, $form_state);
  $form = $form_builder
    ->retrieveForm($form_id, $form_state);
  $form_builder
    ->prepareForm($form_id, $form, $form_state);

  // Set up $form_state so that the form is properly submitted.
  $form_state
    ->setUserInput([
    'form_id' => $form_id,
  ]);
  $form_state
    ->setProgrammed();
  $form_state
    ->setSubmitted();
  $form_builder
    ->processForm($form_id, $form, $form_state);
}