home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (views_handler_field_date.test)

This example Drupal source code file (views_handler_field_date.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

ago, array, created, custom, debug, format, format_date, function, maps, php, return, small, time, views_handler_field_date

The views_handler_field_date.test Drupal example source code

<?php
// $Id: views_handler_field_date.test,v 1.1.2.1 2010/11/07 11:32:25 dereine Exp $

class ViewsHandlerFieldDateTest extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Field: Date',
      'description' => 'Test the core views_handler_field_date handler.',
      'group' => 'Views Handlers',
    );
  }

  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',
        // c is iso 8601 date format @see http://php.net/manual/en/function.date.php
        'custom_date_format' => 'c',
      ),
    ));
    $time = gmmktime(0, 0, 0, 1, 1, 2000);

    $maps = array(
      'small' => format_date($time, 'small'),
      'medium' => format_date($time, 'medium'),
      'large' => format_date($time, 'large'),
      'custom' => format_date($time, 'custom', 'c'),
      '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->executeView($view);

    foreach ($maps as $date_format => $expected_result) {
      $view->field['created']->options['date_format'] = $date_format;
      $this->assertEqual($expected_result, $view->field['created']->advanced_render($view->result[0]));
      debug($view->field['created']->advanced_render($view->result[0]));
    }
    debug($view->result);
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal views_handler_field_date.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.