You are here

public function BookBreadcrumbTest::testBreadcrumbTitleUpdates in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/book/tests/src/Functional/BookBreadcrumbTest.php \Drupal\Tests\book\Functional\BookBreadcrumbTest::testBreadcrumbTitleUpdates()

Tests that the breadcrumb is updated when book content changes.

File

core/modules/book/tests/src/Functional/BookBreadcrumbTest.php, line 162

Class

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

Namespace

Drupal\Tests\book\Functional

Code

public function testBreadcrumbTitleUpdates() {

  // Create a new book.
  $nodes = $this
    ->createBreadcrumbBook();
  $book = $this->book;
  $this
    ->drupalLogin($this->bookAuthor);
  $this
    ->drupalGet($nodes[4]
    ->toUrl());

  // Fetch each node title in the current breadcrumb.
  $links = $this
    ->xpath('//nav[@class="breadcrumb"]/ol/li/a');
  $got_breadcrumb = [];
  foreach ($links as $link) {
    $got_breadcrumb[] = $link
      ->getText();
  }

  // Home link and four parent book nodes should be in the breadcrumb.
  $this
    ->assertCount(5, $got_breadcrumb);
  $this
    ->assertEquals($nodes[3]
    ->getTitle(), end($got_breadcrumb));
  $edit = [
    'title[0][value]' => 'Updated node5 title',
  ];
  $this
    ->drupalGet($nodes[3]
    ->toUrl('edit-form'));
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet($nodes[4]
    ->toUrl());

  // Fetch each node title in the current breadcrumb.
  $links = $this
    ->xpath('//nav[@class="breadcrumb"]/ol/li/a');
  $got_breadcrumb = [];
  foreach ($links as $link) {
    $got_breadcrumb[] = $link
      ->getText();
  }
  $this
    ->assertCount(5, $got_breadcrumb);
  $this
    ->assertEquals($edit['title[0][value]'], end($got_breadcrumb));
}