public function BookTest::testBookListing in Drupal 8
Same name and namespace in other branches
- 9 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookListing()
- 10 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookListing()
Tests the listing of all books.
File
- core/
modules/ book/ tests/ src/ Functional/ BookTest.php, line 506
Class
- BookTest
- Create a book, add pages, and test book interface.
Namespace
Drupal\Tests\book\FunctionalCode
public function testBookListing() {
// Uninstall 'node_access_test' as this interferes with the test.
\Drupal::service('module_installer')
->uninstall([
'node_access_test',
]);
// Create a new book.
$nodes = $this
->createBook();
// Load the book page and assert the created book title is displayed.
$this
->drupalGet('book');
$this
->assertText($this->book
->label(), 'The book title is displayed on the book listing page.');
// Unpublish the top book page and confirm that the created book title is
// not displayed for anonymous.
$this->book
->setUnpublished();
$this->book
->save();
$this
->drupalGet('book');
$this
->assertSession()
->pageTextNotContains($this->book
->label());
// Publish the top book page and unpublish a page in the book and confirm
// that the created book title is displayed for anonymous.
$this->book
->setPublished();
$this->book
->save();
$nodes[0]
->setUnpublished();
$nodes[0]
->save();
$this
->drupalGet('book');
$this
->assertSession()
->pageTextContains($this->book
->label());
// Unpublish the top book page and confirm that the created book title is
// displayed for user which has 'view own unpublished content' permission.
$this
->drupalLogin($this->bookAuthor);
$this->book
->setUnpublished();
$this->book
->save();
$this
->drupalGet('book');
$this
->assertSession()
->pageTextContains($this->book
->label());
// Ensure the user doesn't see the book if they don't own it.
$this->book
->setOwner($this->webUser)
->save();
$this
->drupalGet('book');
$this
->assertSession()
->pageTextNotContains($this->book
->label());
// Confirm that the created book title is displayed for user which has
// 'view any unpublished content' permission.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('book');
$this
->assertSession()
->pageTextContains($this->book
->label());
}