function BookTest::createBookNode

Create book node.

Parameters

integer $book_nid Book node id or set to 'new' to create new book.:

integer $parent Parent book reference id.:

2 calls to BookTest::createBookNode()
BookTest::createBook in drupal/core/modules/book/lib/Drupal/book/Tests/BookTest.php
Create a new book with a page hierarchy.
BookTest::testBook in drupal/core/modules/book/lib/Drupal/book/Tests/BookTest.php
Test book functionality through node interfaces.

File

drupal/core/modules/book/lib/Drupal/book/Tests/BookTest.php, line 209
Definition of Drupal\book\Tests\BookTest.

Class

BookTest

Namespace

Drupal\book\Tests

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_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;
}