You are here

public function DateTimezoneTest::testTimezone in Date 8

Same name in this branch
  1. 8 lib/Drupal/date/Tests/DateTimezoneTest.php \Drupal\date\Tests\DateTimezoneTest::testTimezone()
  2. 8 date_field/lib/Drupal/date_field/Tests/DateTimezoneTest.php \Drupal\date\Tests\DateTimezoneTest::testTimezone()

@todo.

File

date_field/lib/Drupal/date_field/Tests/DateTimezoneTest.php, line 27
Timezone tests.

Class

DateTimezoneTest

Namespace

Drupal\date\Tests

Code

public function testTimezone() {

  // Create a date fields with combinations of various timezone handling and
  // granularity.
  foreach (array(
    'date',
  ) as $field_type) {
    foreach (array(
      'site',
      'none',
      'date',
      'user',
      'utc',
    ) 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 = DateGranularity::arrayFromPrecision($max_granularity);
        $options = array(
          'label' => $label,
          'widget_type' => 'date_popup',
          '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
          ->dateForm($field_name, $field_type, $max_granularity, $tz_handling);
        $this
          ->deleteDateField($label);
      }
    }
  }
}