function BookTest::testBook in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/book/src/Tests/BookTest.php \Drupal\book\Tests\BookTest::testBook()
Tests book functionality through node interfaces.
File
- core/
modules/ book/ src/ Tests/ BookTest.php, line 172 - Contains \Drupal\book\Tests\BookTest.
Class
- BookTest
- Create a book, add pages, and test book interface.
Namespace
Drupal\book\TestsCode
function testBook() {
// Create new book.
$nodes = $this
->createBook();
$book = $this->book;
$this
->drupalLogin($this->webUser);
// Check that book pages display along with the correct outlines and
// previous/next links.
$this
->checkBookNode($book, array(
$nodes[0],
$nodes[3],
$nodes[4],
), FALSE, FALSE, $nodes[0], array());
$this
->checkBookNode($nodes[0], array(
$nodes[1],
$nodes[2],
), $book, $book, $nodes[1], array(
$book,
));
$this
->checkBookNode($nodes[1], NULL, $nodes[0], $nodes[0], $nodes[2], array(
$book,
$nodes[0],
));
$this
->checkBookNode($nodes[2], NULL, $nodes[1], $nodes[0], $nodes[3], array(
$book,
$nodes[0],
));
$this
->checkBookNode($nodes[3], NULL, $nodes[2], $book, $nodes[4], array(
$book,
));
$this
->checkBookNode($nodes[4], NULL, $nodes[3], $book, FALSE, array(
$book,
));
$this
->drupalLogout();
$this
->drupalLogin($this->bookAuthor);
// Check the presence of expected cache tags.
$this
->drupalGet('node/add/book');
$this
->assertCacheTag('config:book.settings');
/*
* Add Node 5 under Node 3.
* Book
* |- Node 0
* |- Node 1
* |- Node 2
* |- Node 3
* |- Node 5
* |- Node 4
*/
$nodes[] = $this
->createBookNode($book
->id(), $nodes[3]->book['nid']);
// Node 5.
$this
->drupalLogout();
$this
->drupalLogin($this->webUser);
// Verify the new outline - make sure we don't get stale cached data.
$this
->checkBookNode($nodes[3], array(
$nodes[5],
), $nodes[2], $book, $nodes[5], array(
$book,
));
$this
->checkBookNode($nodes[4], NULL, $nodes[5], $book, FALSE, array(
$book,
));
$this
->drupalLogout();
// Create a second book, and move an existing book page into it.
$this
->drupalLogin($this->bookAuthor);
$other_book = $this
->createBookNode('new');
$node = $this
->createBookNode($book
->id());
$edit = array(
'book[bid]' => $other_book
->id(),
);
$this
->drupalPostForm('node/' . $node
->id() . '/edit', $edit, t('Save'));
$this
->drupalLogout();
$this
->drupalLogin($this->webUser);
// Check that the nodes in the second book are displayed correctly.
// First we must set $this->book to the second book, so that the
// correct regex will be generated for testing the outline.
$this->book = $other_book;
$this
->checkBookNode($other_book, array(
$node,
), FALSE, FALSE, $node, array());
$this
->checkBookNode($node, NULL, $other_book, $other_book, FALSE, array(
$other_book,
));
// Test that we can save a book programatically.
$this
->drupalLogin($this->bookAuthor);
$book = $this
->createBookNode('new');
$book
->save();
}