You are here

public function BookBreadcrumbTest::testBreadcrumbAccessUpdates in Drupal 8

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

Test that the breadcrumb is updated when book access changes.

File

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

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
    ->drupalPostForm($nodes[3]
    ->toUrl('edit-form'), $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
    ->assertEqual($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
    ->assertEqual($nodes[2]
    ->getTitle(), end($got_breadcrumb));
  $this
    ->drupalGet($nodes[3]
    ->toUrl());
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}