You are here

public function BookBreadcrumbTest::testBreadcrumbAccessUpdates 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::testBreadcrumbAccessUpdates()

Tests that the breadcrumb is updated when book access changes.

File

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

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[@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));
  $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[@class="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);
}