public function TimezoneTest::buildForm in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php \Drupal\KernelTests\Core\Datetime\Element\TimezoneTest::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- core/
tests/ Drupal/ KernelTests/ Core/ Datetime/ Element/ TimezoneTest.php, line 89
Class
- TimezoneTest
- Tests the timezone handling of datetime and datelist element types.
Namespace
Drupal\KernelTests\Core\Datetime\ElementCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['test1'] = [
'#title' => 'No default date, #date_timezone present',
'#type' => $this->elementType,
'#default_value' => '',
'#date_timezone' => $this->timezones['zone A'],
'#test_expect_timezone' => 'zone A',
];
$form['test2'] = [
'#title' => 'No default date, no #date_timezone',
'#type' => $this->elementType,
'#default_value' => '',
'#test_expect_timezone' => 'user',
];
$form['test3'] = [
'#title' => 'Default date present with default timezone, #date_timezone same',
'#type' => $this->elementType,
'#default_value' => $this->date,
'#date_timezone' => $this->timezones['user'],
'#test_expect_timezone' => 'user',
];
$form['test4'] = [
'#title' => 'Default date present with default timezone, #date_timezone different',
'#type' => $this->elementType,
'#default_value' => $this->date,
'#date_timezone' => $this->timezones['zone A'],
'#test_expect_timezone' => 'zone A',
];
$form['test5'] = [
'#title' => 'Default date present with default timezone, no #date_timezone',
'#type' => $this->elementType,
'#default_value' => $this->date,
'#test_expect_timezone' => 'user',
];
$dateWithTimeZoneA = clone $this->date;
$dateWithTimeZoneA
->setTimezone(new \DateTimeZone($this->timezones['zone A']));
$form['test6'] = [
'#title' => 'Default date present with unusual timezone, #date_timezone same',
'#type' => $this->elementType,
'#default_value' => $dateWithTimeZoneA,
'#date_timezone' => $this->timezones['zone A'],
'#test_expect_timezone' => 'zone A',
];
$form['test7'] = [
'#title' => 'Default date present with unusual timezone, #date_timezone different',
'#type' => $this->elementType,
'#default_value' => $dateWithTimeZoneA,
'#date_timezone' => $this->timezones['zone B'],
'#test_expect_timezone' => 'zone B',
];
$form['test8'] = [
'#title' => 'Default date present with unusual timezone, no #date_timezone',
'#type' => $this->elementType,
'#default_value' => $dateWithTimeZoneA,
'#test_expect_timezone' => 'user',
];
$this->testConditions = 8;
return $form;
}