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.
I like your Views series ! Keep it coming please :)