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

Drupal example source code file (views_handler_sort.test)

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

age, array, field, function, id, match, name, number, of, php, rows, table, view, views_test_name

The views_handler_sort.test Drupal example source code

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

/**
 * Test for core views_handler_sort handler.
 */
class ViewsHandlerSortTest extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => t('Sort: generic'),
      'description' => t('Test the core views_handler_sort handler.'),
      'group' => t('Views Handlers'),
    );
  }

  /**
   * Test numeric ordering of the result set.
   */
  public function testNumericOrdering() {
    $view = $this->getBasicView();

    // Change the ordering
    $view->display['default']->handler->override_option('sorts', array(
      'age' => array(
        'order' => 'ASC',
        'id' => 'age',
        'table' => 'views_test',
        'field' => 'age',
        'relationship' => 'none',
      ),
    ));

    // Execute the view.
    $this->executeView($view);

    // Verify the result.
    $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
    $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age'), array(
      'views_test_name' => 'name',
      'views_test_age' => 'age',
    ));

    $view = $this->getBasicView();

    // Reverse the ordering
    $view->display['default']->handler->override_option('sorts', array(
      'age' => array(
        'order' => 'DESC',
        'id' => 'age',
        'table' => 'views_test',
        'field' => 'age',
        'relationship' => 'none',
      ),
    ));

    // Execute the view.
    $this->executeView($view);

    // Verify the result.
    $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
    $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age', TRUE), array(
      'views_test_name' => 'name',
      'views_test_age' => 'age',
    ));
  }

  /**
   * Test string ordering of the result set.
   */
  public function testStringOrdering() {
    $view = $this->getBasicView();

    // Change the ordering
    $view->display['default']->handler->override_option('sorts', array(
      'name' => array(
        'order' => 'ASC',
        'id' => 'name',
        'table' => 'views_test',
        'field' => 'name',
        'relationship' => 'none',
      ),
    ));

    // Execute the view.
    $this->executeView($view);

    // Verify the result.
    $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
    $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name'), array(
      'views_test_name' => 'name',
      'views_test_age' => 'age',
    ));

    $view = $this->getBasicView();

    // Reverse the ordering
    $view->display['default']->handler->override_option('sorts', array(
      'name' => array(
        'order' => 'DESC',
        'id' => 'name',
        'table' => 'views_test',
        'field' => 'name',
        'relationship' => 'none',
      ),
    ));

    // Execute the view.
    $this->executeView($view);

    // Verify the result.
    $this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
    $this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name', TRUE), array(
      'views_test_name' => 'name',
      'views_test_age' => 'age',
    ));
  }
}

Other Drupal examples (source code examples)

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