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

Drupal example source code file (views_handler_field_math.test)

This example Drupal source code file (views_handler_field_math.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

100, array, data, expression, field, function, math, php, public, rand1, rand2, return, view, views

The views_handler_field_math.test Drupal example source code

<?php
// $Id: views_handler_field_math.test,v 1.1.2.1 2010/12/24 14:05:39 dereine Exp $

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

  function viewsData() {
    $data = parent::viewsData();
    return $data;
  }

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

    // Alter the text of the field to a random string.
    $rand1 = rand(0, 100);
    $rand2 = rand(0, 100);
    $view->display['default']->handler->override_option('fields', array(
      'expression' => array(
        'id' => 'expression',
        'table' => 'views',
        'field' => 'expression',
        'relationship' => 'none',
        'expression' => $rand1 . ' + ' . $rand2,
      ),
    ));

    $this->executeView($view);

    $this->assertEqual($rand1 + $rand2, $view->field['expression']->render($view->result[0]));
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal views_handler_field_math.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.