| 7 book.test | BookTestCase::createBookNode($book_nid, $parent = NULL) |
| 8 book.test | BookTestCase::createBookNode($book_nid, $parent = NULL) |
Create book node.
Parameters
integer $book_nid Book node id or set to 'new' to create new book.:
integer $parent Parent book reference id.:
File
- modules/
book/ book.test, line 196 - Tests for book.module.
Code
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_NONE;
$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), t('Book node found in database.'));
$number++;
return $node;
}
Login or register to post comments