- <?php
-
- * @file
- * Definition of ViewsHandlerFieldDateTest.
- */
-
- require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
-
- * Tests the core views_handler_field_date handler.
- */
- class ViewsHandlerFieldDateTest extends ViewsSqlTest {
- function viewsData() {
- $data = parent::viewsData();
- $data['views_test']['created']['field']['handler'] = 'views_handler_field_date';
- return $data;
- }
-
- 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',
-
-
- '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))),
-
- );
- $this->assertRenderedDatesEqual($view, $intervals);
- }
-
- protected function assertRenderedDatesEqual($view, $map, $timezone = NULL) {
- foreach ($map as $date_format => $expected_result) {
- $view->field['created']->options['date_format'] = $date_format;
- $t_args = array(
- '%value' => $expected_result,
- '%format' => $date_format,
- );
- if (isset($timezone)) {
- $t_args['%timezone'] = $timezone;
- $message = t('Value %value in %format format for timezone %timezone matches.', $t_args);
- $view->field['created']->options['timezone'] = $timezone;
- }
- else {
- $message = t('Value %value in %format format matches.', $t_args);
- }
- $actual_result = $view->field['created']->advanced_render($view->result[0]);
- $this->assertEqual($expected_result, $actual_result, $message);
- }
- }
- }