Writing a test for book_get_books()
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
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@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
On 21-Jan-09, at 2:33 AM, Steven Jones wrote:
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.
Thanks! The latest patch on that allows my test to pass and fail as expected. --Andrew
participants (2)
-
Andrew Berry -
Steven Jones