function BookBreadcrumbTest::testBreadcrumbAccessUpdates

Same name and namespace in other branches
  1. 8.9.x core/modules/book/tests/src/Functional/BookBreadcrumbTest.php \Drupal\Tests\book\Functional\BookBreadcrumbTest::testBreadcrumbAccessUpdates()
  2. 10 core/modules/book/tests/src/Functional/BookBreadcrumbTest.php \Drupal\Tests\book\Functional\BookBreadcrumbTest::testBreadcrumbAccessUpdates()
  3. 11.x 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);
}

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