You are here

public function BookTestTrait::createBook in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/book/tests/src/Functional/BookTestTrait.php \Drupal\Tests\book\Functional\BookTestTrait::createBook()

Creates a new book with a page hierarchy.

Parameters

array $edit: (optional) Field data in an associative array. Changes the current input fields (where possible) to the values indicated. Defaults to an empty array.

Return value

\Drupal\node\NodeInterface[]

12 calls to BookTestTrait::createBook()
BookContentModerationTest::testBookWithPendingRevisions in core/modules/book/tests/src/Functional/BookContentModerationTest.php
Tests that book drafts can not modify the book outline.
BookTest::testAdminBookListing in core/modules/book/tests/src/Functional/BookTest.php
Tests the administrative listing of all books.
BookTest::testAdminBookNodeListing in core/modules/book/tests/src/Functional/BookTest.php
Tests the administrative listing of all book pages in a book.
BookTest::testBook in core/modules/book/tests/src/Functional/BookTest.php
Tests book functionality through node interfaces.
BookTest::testBookDelete in core/modules/book/tests/src/Functional/BookTest.php
Tests the access for deleting top-level book nodes.

... See full list

File

core/modules/book/tests/src/Functional/BookTestTrait.php, line 39

Class

BookTestTrait
Provides common functionality for Book test classes.

Namespace

Drupal\Tests\book\Functional

Code

public function createBook($edit = []) {

  // Create new book.
  $this
    ->drupalLogin($this->bookAuthor);
  $this->book = $this
    ->createBookNode('new', NULL, $edit);
  $book = $this->book;

  /*
   * Add page hierarchy to book.
   * Book
   *  |- Node 0
   *   |- Node 1
   *   |- Node 2
   *  |- Node 3
   *  |- Node 4
   */
  $nodes = [];

  // Node 0.
  $nodes[] = $this
    ->createBookNode($book
    ->id(), NULL, $edit);

  // Node 1.
  $nodes[] = $this
    ->createBookNode($book
    ->id(), $nodes[0]->book['nid'], $edit);

  // Node 2.
  $nodes[] = $this
    ->createBookNode($book
    ->id(), $nodes[0]->book['nid'], $edit);

  // Node 3.
  $nodes[] = $this
    ->createBookNode($book
    ->id(), NULL, $edit);

  // Node 4.
  $nodes[] = $this
    ->createBookNode($book
    ->id(), NULL, $edit);
  $this
    ->drupalLogout();
  return $nodes;
}