function DatetimeFormElementTest::testNoErrorMetOnFormSubmit

Checks we have no errors on form submit.

@covers ::validateDatetime

File

core/tests/Drupal/KernelTests/Core/Datetime/Element/DatetimeFormElementTest.php, line 94

Class

DatetimeFormElementTest
Tests static callbacks returns and form submission with datetime elements.

Namespace

Drupal\KernelTests\Core\Datetime\Element

Code

public function testNoErrorMetOnFormSubmit() : void {
    // No error expected when form elements have no value.
    $form_state = new FormState();
    $this->formBuilder
        ->submitForm($this, $form_state);
    $this->assertEmpty($form_state->getErrors());
    // No error expected when a datetime-local element has a valid value.
    $form_state = new FormState();
    $form_state->setValue('datetime_local_picker', [
        'date' => '2025-02-18T12:00',
    ]);
    $this->formBuilder
        ->submitForm($this, $form_state);
    $this->assertEmpty($form_state->getErrors());
}

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