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

Drupal example source code file (views_handler_filter_in_operator.test)

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

30, age, array, expected_result, function, id, in, name, php, return, value, view, views_handler_filter_in_operator, views_test_name

The views_handler_filter_in_operator.test Drupal example source code

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

class ViewsHandlerFilterInOperator extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Filter: in_operator',
      'description' => 'Test the core views_handler_filter_in_operator handler.',
      'group' => 'Views Handlers',
    );
  }

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

    return $data;
  }

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

    // Add a in_operator ordering.
    $view->display['default']->handler->override_option('filters', array(
      'age' => array(
        'id' => 'age',
        'field' => 'age',
        'table' => 'views_test',
        'value' => array(26, 30),
        'operator' => 'in',
      ),
    ));

    $this->executeView($view);

    $expected_result = array(
      array(
        'name' => 'Paul',
        'age' => 26,
      ),
      array(
        'name' => 'Meredith',
        'age' => 30,
      ),
    );

    $this->assertEqual(2, count($view->result));
    $this->assertIdenticalResultset($view, $expected_result, array(
      'views_test_name' => 'name',
      'views_test_age' => 'age',
    ));

    $view->delete();
    $view = $this->getBasicView();

    // Add a in_operator ordering.
    $view->display['default']->handler->override_option('filters', array(
      'age' => array(
        'id' => 'age',
        'field' => 'age',
        'table' => 'views_test',
        'value' => array(26, 30),
        'operator' => 'not in',
      ),
    ));

    $this->executeView($view);

    $expected_result = array(
      array(
        'name' => 'John',
        'age' => 25,
      ),
      array(
        'name' => 'George',
        'age' => 27,
      ),
      array(
        'name' => 'Ringo',
        'age' => 28,
      ),
    );

    $this->assertEqual(3, count($view->result));
    $this->assertIdenticalResultset($view, $expected_result, 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_filter_in_operator.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.