You are here

public function BookTest::testBookOutline in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/book/src/Tests/BookTest.php \Drupal\book\Tests\BookTest::testBookOutline()

Tests outline of a book.

File

core/modules/book/src/Tests/BookTest.php, line 531
Contains \Drupal\book\Tests\BookTest.

Class

BookTest
Create a book, add pages, and test book interface.

Namespace

Drupal\book\Tests

Code

public function testBookOutline() {
  $this
    ->drupalLogin($this->bookAuthor);

  // Create new node not yet a book.
  $empty_book = $this
    ->drupalCreateNode(array(
    'type' => 'book',
  ));
  $this
    ->drupalGet('node/' . $empty_book
    ->id() . '/outline');
  $this
    ->assertNoLink(t('Book outline'), 'Book Author is not allowed to outline');
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('node/' . $empty_book
    ->id() . '/outline');
  $this
    ->assertRaw(t('Book outline'));
  $this
    ->assertOptionSelected('edit-book-bid', 0, 'Node does not belong to a book');
  $edit = array();
  $edit['book[bid]'] = '1';
  $this
    ->drupalPostForm('node/' . $empty_book
    ->id() . '/outline', $edit, t('Add to book outline'));
  $node = \Drupal::entityManager()
    ->getStorage('node')
    ->load($empty_book
    ->id());

  // Test the book array.
  $this
    ->assertEqual($node->book['nid'], $empty_book
    ->id());
  $this
    ->assertEqual($node->book['bid'], $empty_book
    ->id());
  $this
    ->assertEqual($node->book['depth'], 1);
  $this
    ->assertEqual($node->book['p1'], $empty_book
    ->id());
  $this
    ->assertEqual($node->book['pid'], '0');

  // Create new book.
  $this
    ->drupalLogin($this->bookAuthor);
  $book = $this
    ->createBookNode('new');
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('node/' . $book
    ->id() . '/outline');
  $this
    ->assertRaw(t('Book outline'));

  // Create a new node and set the book after the node was created.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'book',
  ));
  $edit = array();
  $edit['book[bid]'] = $node
    ->id();
  $this
    ->drupalPostForm('node/' . $node
    ->id() . '/edit', $edit, t('Save'));
  $node = \Drupal::entityManager()
    ->getStorage('node')
    ->load($node
    ->id());

  // Test the book array.
  $this
    ->assertEqual($node->book['nid'], $node
    ->id());
  $this
    ->assertEqual($node->book['bid'], $node
    ->id());
  $this
    ->assertEqual($node->book['depth'], 1);
  $this
    ->assertEqual($node->book['p1'], $node
    ->id());
  $this
    ->assertEqual($node->book['pid'], '0');

  // Test the form itself.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertOptionSelected('edit-book-bid', $node
    ->id());
}