function DatetimeElementFormTest::testTimezoneHandling

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::testTimezoneHandling()
  2. 10 core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::testTimezoneHandling()
  3. 11.x core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::testTimezoneHandling()

Tests proper timezone handling of the Datetime element.

File

core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php, line 114

Class

DatetimeElementFormTest
Tests DatetimeElement functionality.

Namespace

Drupal\KernelTests\Core\Datetime

Code

public function testTimezoneHandling() {
    // Render the form once with the site's timezone.
    $form = \Drupal::formBuilder()->getForm($this);
    $this->render($form);
    $this->assertEquals('Australia/Sydney', $form['datetime_element']['#date_timezone']);
    // Mimic a user with a different timezone than Australia/Sydney.
    date_default_timezone_set('UTC');
    $form = \Drupal::formBuilder()->getForm($this);
    $this->render($form);
    $this->assertEquals('UTC', $form['datetime_element']['#date_timezone']);
}

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