function BookTest::testAdminBookNodeListing

Same name in other branches
  1. 9 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testAdminBookNodeListing()
  2. 8.9.x core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testAdminBookNodeListing()
  3. 10 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testAdminBookNodeListing()

Tests the administrative listing of all book pages in a book.

File

core/modules/book/tests/src/Functional/BookTest.php, line 618

Class

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

Namespace

Drupal\Tests\book\Functional

Code

public function testAdminBookNodeListing() {
    // Create a new book.
    $nodes = $this->createBook();
    $this->drupalLogin($this->adminUser);
    // Load the book page list and assert the created book title is displayed
    // and action links are shown on list items.
    $this->drupalGet('admin/structure/book/' . $this->book
        ->id());
    $this->assertSession()
        ->pageTextContains($this->book
        ->label());
    // Test that the view link is found from the list.
    $this->assertSession()
        ->elementTextEquals('xpath', '//table//ul[@class="dropbutton"]/li/a', 'View');
    // Test that all the book pages are displayed on the book outline page.
    $this->assertSession()
        ->elementsCount('xpath', '//table//ul[@class="dropbutton"]/li/a', count($nodes));
    // Unpublish a book in the hierarchy.
    $nodes[0]->setUnPublished();
    $nodes[0]->save();
    // Node should still appear on the outline for admins.
    $this->drupalGet('admin/structure/book/' . $this->book
        ->id());
    $this->assertSession()
        ->elementsCount('xpath', '//table//ul[@class="dropbutton"]/li/a', count($nodes));
    // Saving a book page not as the current version shouldn't effect the book.
    $old_title = $nodes[1]->getTitle();
    $new_title = $this->getRandomGenerator()
        ->name();
    $nodes[1]->isDefaultRevision(FALSE);
    $nodes[1]->setNewRevision(TRUE);
    $nodes[1]->setTitle($new_title);
    $nodes[1]->save();
    $this->drupalGet('admin/structure/book/' . $this->book
        ->id());
    $this->assertSession()
        ->elementsCount('xpath', '//table//ul[@class="dropbutton"]/li/a', count($nodes));
    $this->assertSession()
        ->responseNotContains($new_title);
    $this->assertSession()
        ->responseContains($old_title);
}

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