function BookTestCase::createBookNode

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.

2 calls to BookTestCase::createBookNode()
BookTestCase::createBook in drupal/modules/book/book.test
Creates a new book with a page hierarchy.
BookTestCase::testBook in drupal/modules/book/book.test
Tests book functionality through node interfaces.

File

drupal/modules/book/book.test, line 227
Tests for book.module.

Class

BookTestCase
Tests the functionality of the 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, 'Book node found in database.');
  $number++;
  return $node;
}