function TimezoneTest::buildForm

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php \Drupal\KernelTests\Core\Datetime\Element\TimezoneTest::buildForm()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php \Drupal\KernelTests\Core\Datetime\Element\TimezoneTest::buildForm()
  3. 11.x core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php \Drupal\KernelTests\Core\Datetime\Element\TimezoneTest::buildForm()

Overrides FormInterface::buildForm

File

core/tests/Drupal/KernelTests/Core/Datetime/Element/TimezoneTest.php, line 91

Class

TimezoneTest
Tests the timezone handling of datetime and datelist element types.

Namespace

Drupal\KernelTests\Core\Datetime\Element

Code

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

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