public function ViewsHandlerFieldDateTest::testFieldDate

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

File

tests/handlers/views_handler_field_date.test, line 26
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 iso 8601 date format @see http://php.net/manual/en/function.date.php
      'custom_date_format' => 'c',
      'second_date_format' => 'custom',
      'second_date_format_custom' => '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(
      'small' => format_date($time, 'small', '', $timezone),
      'medium' => format_date($time, 'medium', '', $timezone),
      'large' => format_date($time, 'large', '', $timezone),
      'custom' => format_date($time, 'custom', 'c', $timezone),
      'today time ago custom' => format_date($time, 'custom', 'c', $timezone),
      'today time ago' => t('%time ago', array('%time' => format_interval(120, 2))),
    );
    $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);
}