Create book node.
integer $book_nid Book node id or set to 'new' to create new book.:
integer $parent Parent book reference id.:
function createBookNode($book_nid, $parent = NULL) {
// $number does not use drupal_static as it should not be reset
// since it uniquely identifies each call to createBookNode().
static $number = 0;
// Used to ensure that when sorted nodes stay in same order.
$edit = array();
$langcode = LANGUAGE_NOT_SPECIFIED;
$edit["title"] = $number . ' - SimpleTest test node ' . $this
->randomName(10);
$edit["body[{$langcode}][0][value]"] = 'SimpleTest test body ' . $this
->randomName(32) . ' ' . $this
->randomName(32);
$edit['book[bid]'] = $book_nid;
if ($parent !== NULL) {
$this
->drupalPost('node/add/book', $edit, t('Change book (update list of parents)'));
$edit['book[plid]'] = $parent;
$this
->drupalPost(NULL, $edit, t('Save'));
}
else {
$this
->drupalPost('node/add/book', $edit, t('Save'));
}
// Check to make sure the book node was created.
$node = $this
->drupalGetNodeByTitle($edit['title']);
$this
->assertNotNull($node === FALSE ? NULL : $node, 'Book node found in database.');
$number++;
return $node;
}