1 user.test UserTimeZoneFunctionalTest::testUserTimeZone()

Tests the display of dates and time when user-configurable time zones are set.


core/modules/user/tests/user.test, line 1647
Tests for user.module.


Tests for user-configurable time zones.


function testUserTimeZone() {
  // Setup date/time settings for Los Angeles time.
    ->set('user_configurable_timezones', 1)
    ->set('default_timezone', 'America/Los_Angeles')

  // Include the timezone in the medium date format.
  $format = system_date_format_load('medium');
  $format['pattern'] = 'Y-m-d H:i T';

  // Create a user account and login.
  $web_user = $this->backdropCreateUser();

  // Create some nodes with different authored-on dates.
  // One date in PST (winter time):
  $date1 = '2007-03-09 21:00:00 -0800';
  // Two dates in PDT (summer time):
  $date2 = '2007-03-12 01:00:00 -0700';
  $date3 = '2007-03-25 21:00:00 -0700';
  $node1 = $this->backdropCreateNode(array('created' => strtotime($date1), 'type' => 'post'));
  $node2 = $this->backdropCreateNode(array('created' => strtotime($date2), 'type' => 'post'));
  $node3 = $this->backdropCreateNode(array('created' => strtotime($date3), 'type' => 'post'));

  // Confirm date format and time zone.
  $this->assertText('2007-03-09 21:00 PST', 'Date should be PST.');
  $this->assertText('2007-03-12 01:00 PDT', 'Date should be PDT.');
  $this->assertText('2007-03-25 21:00 PDT', 'Date should be PDT.');

  // Change user time zone to Santiago time.
  $edit = array();
  $edit['mail'] = $web_user->mail;
  $edit['timezone'] = 'Europe/Paris';
  $this->backdropPost("user/$web_user->uid/edit", $edit, t('Save'));
  $this->assertText(t('The changes have been saved.'), 'Time zone changed to Central Europe time.');

  // Confirm date format and time zone.
  $this->assertText('2007-03-10 06:00 CET', 'Date should be Central European Time; nine hours ahead of PST.');
  $this->assertText('2007-03-12 09:00 CET', 'Date should be Central European Time; eight hours ahead of PDT');
  $this->assertText('2007-03-26 06:00 CEST', 'Date should be Central European Summer Time; nine hours ahead of PDT.');