function DatetimeElementFormTest::testTimezoneHandling

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::testTimezoneHandling()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::testTimezoneHandling()
  3. 10 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 198

Class

DatetimeElementFormTest
Tests DatetimeElement functionality.

Namespace

Drupal\KernelTests\Core\Datetime

Code

public function testTimezoneHandling() : void {
    // 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.