You are here

public function DatetimeElementFormTest::testTimezoneHandling in Drupal 10

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

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']);
}