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

Drupal example source code file (views_handler_field_file_size.test)

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

1000, 10000, age, array, bytes, data, extends, field, function, php, public, return, view, views_handler_field_file_size

The views_handler_field_file_size.test Drupal example source code

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

/**
 * @see CommonXssUnitTest
 */
class ViewsHandlerTestFileSize extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Field: file_size',
      'description' => 'Test the core views_handler_field_file_size handler.',
      'group' => 'Views Handlers',
    );
  }

  function dataSet() {
    $data = parent::dataSet();
    $data[0]['age'] = 0;
    $data[1]['age'] = 10;
    $data[2]['age'] = 1000;
    $data[3]['age'] = 10000;

    return $data;
  }

  function viewsData() {
    $data = parent::viewsData();
    $data['views_test']['age']['field']['handler'] = 'views_handler_field_file_size';

    return $data;
  }

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

    $view->display['default']->handler->override_option('fields', array(
      'age' => array(
        'id' => 'age',
        'table' => 'views_test',
        'field' => 'age',
      ),
    ));

    $this->executeView($view);

    // Test with the formatted option.
    $this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
    $this->assertEqual($view->field['age']->advanced_render($view->result[1]), '10 bytes');
    $this->assertEqual($view->field['age']->advanced_render($view->result[2]), '1000 bytes');
    $this->assertEqual($view->field['age']->advanced_render($view->result[3]), '9.77 KB');
    // Test with the bytes option.
    $view->field['age']->options['file_size_display'] = 'bytes';
    $this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
    $this->assertEqual($view->field['age']->advanced_render($view->result[1]), 10);
    $this->assertEqual($view->field['age']->advanced_render($view->result[2]), 1000);
    $this->assertEqual($view->field['age']->advanced_render($view->result[3]), 10000);
  }
}

Other Drupal examples (source code examples)

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