1.20.x views_handler_field_date.test public ViewsHandlerFieldDateTest::testFieldDate()

File

modules/views/tests/handlers/views_handler_field_date.test, line 20
Definition of ViewsHandlerFieldDateTest.

Class

ViewsHandlerFieldDateTest
Tests the core views_handler_field_date handler.

Code

public function testFieldDate() {
  $view = $this->getBasicView();

  $view->display['default']->handler->override_option('fields', array(
    'created' => array(
      'id' => 'created',
      'table' => 'views_test',
      'field' => 'created',
      'relationship' => 'none',
      // c is the ISO 8601 date format (yyyy-mm-ddThh:mm:ss±hh:mm).
      // @see https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters
      'custom_date_format' => 'c',
    ),
  ));
  $time = gmmktime(0, 0, 0, 1, 1, 2000);

  $this->executeView($view);

  $timezones = array(
    NULL,
    'UTC',
    'America/New_York',
  );
  foreach ($timezones as $timezone) {
    $dates = array(
      'short' => format_date($time, 'short', '', $timezone),
      'medium' => format_date($time, 'medium', '', $timezone),
      'long' => format_date($time, 'long', '', $timezone),
      'custom' => format_date($time, 'custom', 'c', $timezone),
    );
    $this->assertRenderedDatesEqual($view, $dates, $timezone);
  }

  $intervals = array(
    'raw time ago' => format_interval(REQUEST_TIME - $time, 2),
    'time ago' => t('%time ago', array('%time' => format_interval(REQUEST_TIME - $time, 2))),
    // TODO write tests for them
//       'raw time span' => format_interval(REQUEST_TIME - $time, 2),
//       'time span' => t('%time hence', array('%time' => format_interval(REQUEST_TIME - $time, 2))),
  );
  $this->assertRenderedDatesEqual($view, $intervals);
}