You are here

protected function SitemapBookTest::createBookNode in Sitemap 8

Same name and namespace in other branches
  1. 8.2 src/Tests/SitemapBookTest.php \Drupal\sitemap\Tests\SitemapBookTest::createBookNode()
  2. 2.0.x src/Tests/SitemapBookTest.php \Drupal\sitemap\Tests\SitemapBookTest::createBookNode()

Creates a book node. From BookTest.

Parameters

int|string $book_nid: A book node ID or set to 'new' to create a new book.

int|null $parent: (optional) Parent book reference ID. Defaults to NULL.

Return value

object Returns object

1 call to SitemapBookTest::createBookNode()
SitemapBookTest::createBook in src/Tests/SitemapBookTest.php
Creates a new book with a page hierarchy. Adapted from BookTest.

File

src/Tests/SitemapBookTest.php, line 125

Class

SitemapBookTest
Test the display of books based on sitemap settings.

Namespace

Drupal\sitemap\Tests

Code

protected 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().
  // Used to ensure that when sorted nodes stay in same order.
  static $number = 0;
  $edit = [];
  $edit['title[0][value]'] = str_pad($number, 2, '0', STR_PAD_LEFT) . ' - SimpleTest test node ' . $this
    ->randomMachineName(10);
  $edit['body[0][value]'] = 'SimpleTest test body ' . $this
    ->randomMachineName(32) . ' ' . $this
    ->randomMachineName(32);
  $edit['book[bid]'] = $book_nid;
  if ($parent !== NULL) {
    $this
      ->drupalPostForm('node/add/book', $edit, t('Change book (update list of parents)'));
    $edit['book[pid]'] = $parent;
    $this
      ->drupalPostForm(NULL, $edit, t('Save'));
  }
  else {
    $this
      ->drupalPostForm('node/add/book', $edit, t('Save'));
  }
  $node = $this
    ->drupalGetNodeByTitle($edit['title[0][value]']);
  $number++;
  return $node;
}