You are here

public function BookBreadcrumbTest::testBreadcrumbAccessUpdates in Drupal 10

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

Tests that the breadcrumb is updated when book access changes.

File

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

Class

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

Namespace

Drupal\Tests\book\Functional

Code

public function testBreadcrumbAccessUpdates() {

  // Create a new book.
  $nodes = $this
    ->createBreadcrumbBook();
  $this
    ->drupalLogin($this->bookAuthor);
  $edit = [
    'title[0][value]' => "you can't see me",
  ];
  $this
    ->drupalGet($nodes[3]
    ->toUrl('edit-form'));
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet($nodes[4]
    ->toUrl());
  $links = $this
    ->xpath('//nav[@aria-labelledby="system-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));
  $config = $this->container
    ->get('config.factory')
    ->getEditable('book_breadcrumb_test.settings');
  $config
    ->set('hide', TRUE)
    ->save();
  $this
    ->drupalGet($nodes[4]
    ->toUrl());
  $links = $this
    ->xpath('//nav[@aria-labelledby="system-breadcrumb"]/ol/li/a');
  $got_breadcrumb = [];
  foreach ($links as $link) {
    $got_breadcrumb[] = $link
      ->getText();
  }
  $this
    ->assertCount(4, $got_breadcrumb);
  $this
    ->assertEquals($nodes[2]
    ->getTitle(), end($got_breadcrumb));
  $this
    ->drupalGet($nodes[3]
    ->toUrl());
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}