[development] Writing a test for book_get_books()

Steven Jones darthsteven at gmail.com
Wed Jan 21 07:33:28 UTC 2009


Drupal execute won't work with the batch API, this might be the source
of the problem, there's an issue here:
http://drupal.org/node/297972
though it hasn't got much attention.

Regards
Steven Jones
ComputerMinds ltd - Perfect Drupal Websites

Phone : 0121 288 0434
Mobile : 07951 270 026
http://www.computerminds.co.uk



2009/1/21 Andrew Berry <andrewberry at sentex.net>:
> Hi,
>
> 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,
> (object)$parent_node);
>
> 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 incorrectly?
> 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.
>
> Thanks,
> --Andrew


More information about the development mailing list