[development] Writing a test for book_get_books()

Andrew Berry andrewberry at sentex.net
Wed Jan 21 02:12:19 UTC 2009


This is in relation to http://drupal.org/node/360377.

What I'm doing is building multiple $form_state arrays and using them  
to build an entire structure of a book automatically. In essence, the  
code looks like this (mostly from the comments above drupal_execute(),  
and yes, I want to create a book of articles - node type doesn't seem  
to matter):

$parent_node = array('type' => 'article');
$form_state = array();
$form_state['values'] = array();
$form_state['values']['title'] = $number . ' - SimpleTest test node  
' . $this->randomName(10);
$form_state['values']['body'] = 'SimpleTest test body ' . $this- 
 >randomName(32) . ' ' . $this->randomName(32);
$form_state['values']['book'] = _book_link_defaults('new');
$form_state['values']['book']['bid'] = 'new';
$form_state['values']['op'] = t('Save');
drupal_execute($parent_node['type'] . '_node_form', $form_state,  

And repeat for the various subpages setting the various book  
properties so that child pages have the right parents.

According to lyricnz2 on IRC (thanks!), the problem is that  
drupal_execute() doesn't work as expected in SimpleTest environments,  
as it runs against the normal database, and not the simpletest copy.

Two questions then:

1) Is the original issue actually a bug, or am I abusing FAPI  
2) Since the issue requires multiple book nodes to be inserted in one  
request, meaning I can't use drupalPost(), how can I write a proper  
test for it? It was suggested that I could create a block and run PHP  
in it, but I would think there has to be a better way.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2672 bytes
Desc: not available
Url : http://lists.drupal.org/pipermail/development/attachments/20090120/c164d0a3/attachment.bin 

More information about the development mailing list