function DatetimeFormElementTest::testDatetimeLocalProcessDatetime
Checks expected values are returned by ::processDatetime().
Test only applied to 'datetime-local' date element.
@covers ::processDatetime
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Datetime/ Element/ DatetimeFormElementTest.php, line 144
Class
- DatetimeFormElementTest
- Tests static callbacks returns and form submission with datetime elements.
Namespace
Drupal\KernelTests\Core\Datetime\ElementCode
public function testDatetimeLocalProcessDatetime() : void {
$form = [
'datetime_local_picker' => [
'#type' => 'datetime',
'#date_date_element' => 'datetime-local',
'#date_date_format' => 'Y-m-d',
'#date_time_element' => 'none',
'#date_time_format' => 'H:i:s',
'#value' => [
'object' => new DrupalDateTime('2025-02-18T12:00'),
'date' => '2025-02-18',
'time' => '12:00:00',
],
'#date_year_range' => '1900:2050',
'#attributes' => [],
'#required' => TRUE,
],
'submit' => [
'#type' => 'submit',
'#value' => 'Submit',
],
];
$element = $form['datetime_local_picker'];
$form_state = new FormState();
$form_state->setValue('datetime_local_picker', [
'date' => '2025-02-18T12:00',
]);
$result = Datetime::processDatetime($element, $form_state, $form);
$this->assertIsArray($result);
$this->assertArrayHasKey('date', $result);
$this->assertIsArray($result['date']);
$this->assertArrayHasKey('#error_no_message', $result['date']);
$this->assertTrue($result['date']['#error_no_message']);
$this->assertArrayHasKey('#attributes', $result['date']);
$this->assertArrayHasKey('min', $result['date']['#attributes']);
$this->assertEquals('1900-01-01T00:00:00', $result['date']['#attributes']['min']);
$this->assertArrayHasKey('max', $result['date']['#attributes']);
$this->assertEquals('2050-12-31T23:59:59', $result['date']['#attributes']['max']);
$this->assertArrayNotHasKey('time', $result);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.