You are here

public function DateTimezoneTestCase::testTimezone in Date 7.2

Same name and namespace in other branches
  1. 7.3 tests/DateTimezoneTestCase.test \DateTimezoneTestCase::testTimezone()

Create a date fields, combining various timezones and granularity.

File

tests/DateTimezoneTestCase.test, line 41
Test timezone handling.

Class

DateTimezoneTestCase
Test timezone handling.

Code

public function testTimezone() {
  foreach (array(
    'date',
    'datestamp',
    'datetime',
  ) as $field_type) {
    foreach (array(
      'site',
      'none',
      'date',
      'user',
      'utc',
      'Europe/Dublin',
    ) as $tz_handling) {
      foreach (array(
        'year',
        'month',
        'day',
        'hour',
        'minute',
        'second',
      ) as $max_granularity) {

        // Skip invalid combinations.
        if (in_array($max_granularity, array(
          'year',
          'month',
          'day',
        )) && $tz_handling !== 'none') {
          continue;
        }
        $field_name = "field_test";
        $label = 'Test';
        $granularity = date_granularity_array_from_precision($max_granularity);
        $options = array(
          'label' => $label,
          'widget_type' => 'date_text',
          'field_name' => $field_name,
          'field_type' => $field_type,
          'input_format' => 'custom',
          'input_format_custom' => 'm/d/Y - H:i:s',
          'tz_handling' => $tz_handling,
          'granularity' => $granularity,
        );
        $this
          ->createDateField($options);
        $this
          ->buildDateForm($field_name, $field_type, $max_granularity, $tz_handling);
        $this
          ->deleteDateField($label);
      }
    }
  }
}