1 book.test | BookTestCase::createBookNode($book_nid, $parent = NULL) |
Creates a book node.
Parameters
$book_nid: A book node ID or set to 'new' to create a new book.
$parent: (optional) Parent book reference ID. Defaults to NULL.
File
- core/
modules/ book/ tests/ book.test, line 219 - Tests for book.module.
Class
- BookTestCase
- Tests the functionality of the Book module.
Code
function createBookNode($book_nid, $parent = NULL) {
// $number does not use backdrop_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->backdropPost('node/add/book', $edit, t('Change book (update list of parents)'));
$edit['book[plid]'] = $parent;
$this->backdropPost(NULL, $edit, t('Save'));
}
else {
$this->backdropPost('node/add/book', $edit, t('Save'));
}
// Check to make sure the book node was created.
$node = $this->backdropGetNodeByTitle($edit['title']);
$this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.');
$number++;
return $node;
}