The drop is always movingYou know that saying about standing on the shoulders of giants? Drupal is standing on a huge pile of midgetsAll content management systems suck, Drupal just happens to suck less.Popular open source software is more secure than unpopular open source software, because insecure software becomes unpopular fast. [That doesn't happen for proprietary software.]Drupal makes sandwiches happen.There is a module for that

Test the Views integration of your module

Submitted by nk on Mon, 2011-07-11 04:50

This might be an old hat to those who are used to creating Views in code, but for me this is a nice new trick. So first create a view in the UI, export it and then cut it down mercilessly. There's extremely little necessary to get a View up and running if you dont care about the display and just want the raw results. First you need

<?php
$view
= new view;
$handler = $view->new_display('default');
?>

Then a field:

<?php
$handler
->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
?>

Then you can add an argument like this

<?php
$handler
->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';

$view->set_arguments(array($this->node1->nid));
?>

Then you can run the view and check the desired results:

<?php
$view
->execute();
$this->assertEqual(count($view->result), $count);
?>

See http://drupalcode.org/project/relation.git/blob/993f8603ff492db7797630bf... here.

A filter only needs an operator and a value more -- you can copy these from the exported view.

Commenting on this Story is closed.

Submitted by Anonymous on Mon, 2011-07-11 07:19.

I like your Views series ! Keep it coming please :)