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

Drupal example source code file (views_argument_validator.test)

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

default, false, function, initially, node, none, null, php, return, string, to, true, view, view_argument_validate_numeric

The views_argument_validator.test Drupal example source code

<?php
// $Id: views_argument_validator.test,v 1.1.4.6 2010/05/24 19:58:36 dereine Exp $

class viewsArgumentValidatorTest extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => t('Argument validator'),
      'group' => t('Views Plugins'),
      'description' => t('Test argument validator tests.'),
    );
  }

  function testArgumentValidatePhp() {
    $string = $this->randomName();
    $view = $this->view_test_argument_validate_php($string);
    $view->set_display('default');
    $view->pre_execute();
    $view->init_handlers();
    $this->assertTrue($view->argument['null']->validate_arg($string));
    // Reset safed argument validation.
    $view->argument['null']->argument_validated = NULL;
    $this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
  }

  function testArgumentValidateNumeric() {
    $view = $this->view_argument_validate_numeric();
    $view->set_display('default');
    $view->pre_execute();
    $view->init_handlers();
    $this->assertFalse($view->argument['null']->validate_arg($this->randomString()));
    // Reset safed argument validation.
    $view->argument['null']->argument_validated = NULL;
    $this->assertTrue($view->argument['null']->validate_arg(12));
  }

  function view_test_argument_validate_php($string) {
    $code = 'return $argument == \''. $string .'\';';
    $view = new view;
    $view->name = 'view_argument_validate_numeric';
    $view->description = '';
    $view->tag = '';
    $view->view_php = '';
    $view->base_table = 'node';
    $view->is_cacheable = FALSE;
    $view->api_version = 2;
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

    /* Display: Defaults */
    $handler = $view->new_display('default', 'Defaults', 'default');
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'full';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';
    /* Argument: Global: Null */
    $handler->display->display_options['arguments']['null']['id'] = 'null';
    $handler->display->display_options['arguments']['null']['table'] = 'views';
    $handler->display->display_options['arguments']['null']['field'] = 'null';
    $handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['null']['validate_type'] = 'php';
    $handler->display->display_options['arguments']['null']['validate_options']['code'] = $code;
    $handler->display->display_options['arguments']['null']['must_not_be'] = 0;

    return $view;
  }

  function view_argument_validate_numeric() {
    $view = new view;
    $view->name = 'view_argument_validate_numeric';
    $view->description = '';
    $view->tag = '';
    $view->view_php = '';
    $view->base_table = 'node';
    $view->is_cacheable = FALSE;
    $view->api_version = 2;
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

    /* Display: Defaults */
    $handler = $view->new_display('default', 'Defaults', 'default');
    $handler->display->display_options['access']['type'] = 'none';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'full';
    $handler->display->display_options['style_plugin'] = 'default';
    $handler->display->display_options['row_plugin'] = 'fields';
    /* Argument: Global: Null */
    $handler->display->display_options['arguments']['null']['id'] = 'null';
    $handler->display->display_options['arguments']['null']['table'] = 'views';
    $handler->display->display_options['arguments']['null']['field'] = 'null';
    $handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
    $handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
    $handler->display->display_options['arguments']['null']['validate_type'] = 'numeric';
    $handler->display->display_options['arguments']['null']['must_not_be'] = 0;

    return $view;
  }
}

Other Drupal examples (source code examples)

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