function BookBreadcrumbTest::testBreadcrumbTitleUpdates

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

Test that the breadcrumb is updated when book content changes.

File

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

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->assertEqual($nodes[3]->getTitle(), end($got_breadcrumb));
    $edit = [
        'title[0][value]' => 'Updated node5 title',
    ];
    $this->drupalPostForm($nodes[3]->toUrl('edit-form'), $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->assertEqual($edit['title[0][value]'], end($got_breadcrumb));
}

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