function BookTest::testBookListing

Same name in other branches
  1. 9 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookListing()
  2. 8.9.x core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookListing()
  3. 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 552

Class

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

Namespace

Drupal\Tests\book\Functional

Code

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->assertSession()
        ->pageTextContains($this->book
        ->label());
    // 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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.