1.20.x date_timezone.test public DateTimezoneTestCase::dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling)

Tests the submission of a date field's widget form when using unlimited cardinality

File

modules/date/tests/date_timezone.test, line 81
Timezone tests.

Class

DateTimezoneTestCase

Code

public function dateMultiValueForm($field_name, $field_type, $max_granularity, $tz_handling) {
  $format = system_date_format_load('long');
  $format['pattern'] = 'D, m/d/Y - H:i:s T';
  system_date_format_save($format);
  $edit = array();
  $should_be = array();
  $edit['title'] = $this->randomName(8);
  $timezones = array('America/Chicago', 'America/Los_Angeles', 'America/New_York');

  switch ($max_granularity) {
    case 'hour':
      $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
      $should_be[0] = 'Thu, 10/07/2010 - 10 CDT';

      $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
      $should_be[1] = 'Thu, 10/07/2010 - 10 PDT';

      $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
      $should_be[2] = 'Thu, 10/07/2010 - 10 EDT';

      break;
    case 'minute':
      $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
      $should_be[0] = 'Thu, 10/07/2010 - 10:30 CDT';

      $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
      $should_be[1] = 'Thu, 10/07/2010 - 10:30 PDT';

      $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
      $should_be[2] = 'Thu, 10/07/2010 - 10:30 EDT';

      break;
    case 'second':
      $edit[$field_name . '[und][0][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][0][timezone][timezone]'] = 'America/Chicago';
      $should_be[0] = 'Thu, 10/07/2010 - 10:30:30 CDT';

      $edit[$field_name . '[und][1][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][1][timezone][timezone]'] = 'America/Los_Angeles';
      $should_be[1] = 'Thu, 10/07/2010 - 10:30:30 PDT';

      $edit[$field_name . '[und][2][value][date]'] = '10/07/2010 - 10:30';
      $edit[$field_name . '[und][2][timezone][timezone]'] = 'America/New_York';
      $should_be[2] = 'Thu, 10/07/2010 - 10:30:30 EDT';
      break;
  }

  $this->backdropPost('node/add/story', $edit, t('Save'));
  $this->assertText($edit['title'], "Node has been created");

  foreach ($should_be as $assertion) {
    $this->assertText($assertion, "Found the correct date for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
  }

  // Goto the edit page and save the node again.
  $node = $this->backdropGetNodeByTitle($edit['title']);
  $this->backdropGet('node/' . $node->nid . '/edit');

  // Re-assert the proper date timezones.
  foreach ($timezones as $key => $timezone) {
    $this->assertOptionSelected('edit-field-test-und-' . $key . '-timezone-timezone', $timezone, "Found the correct timezone $timezone for a $field_type field using $max_granularity granularity with $tz_handling timezone handling.");
  }
}