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

Drupal example source code file (views_handler_field_counter.test)

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

array, counter, extends, field, function, id, name, none, php, rand_start, relationship, table, views, views_test

The views_handler_field_counter.test Drupal example source code

<?php
// $Id: views_handler_field_counter.test,v 1.1.2.2 2010/12/27 08:43:31 dereine Exp $

class viewsHandlerFilterCounterTest extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Field: Counter',
      'description' => 'Tests the views_handler_field_counter handler',
      'group' => 'Views Handlers',
    );
  }

  function testSimple() {
    $view = $this->getBasicView();
    $view->display['default']->handler->override_option('fields', array(
      'counter' => array(
        'id' => 'counter',
        'table' => 'views',
        'field' => 'counter',
        'relationship' => 'none',
      ),
      'name' => array(
        'id' => 'name',
        'table' => 'views_test',
        'field' => 'name',
        'relationship' => 'none',
      ),
    ));
    $view->preview();

    $this->assertEqual(1, $view->style_plugin->rendered_fields[0]['counter']);
    $this->assertEqual(2, $view->style_plugin->rendered_fields[1]['counter']);
    $this->assertEqual(3, $view->style_plugin->rendered_fields[2]['counter']);
    $view->destroy();

    $view = $this->getBasicView();
    $rand_start = rand(5, 10);
    $view->display['default']->handler->override_option('fields', array(
      'counter' => array(
        'id' => 'counter',
        'table' => 'views',
        'field' => 'counter',
        'relationship' => 'none',
        'counter_start' => $rand_start
      ),
      'name' => array(
        'id' => 'name',
        'table' => 'views_test',
        'field' => 'name',
        'relationship' => 'none',
      ),
    ));
    $view->preview();

    $this->assertEqual(0 + $rand_start, $view->style_plugin->rendered_fields[0]['counter']);
    $this->assertEqual(1 + $rand_start, $view->style_plugin->rendered_fields[1]['counter']);
    $this->assertEqual(2 + $rand_start, $view->style_plugin->rendered_fields[2]['counter']);
  }

  // @TODO: Write tests for pager.
  function testPager() {
  }
}

Other Drupal examples (source code examples)

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