function BookTest::testBookNavigationBlock

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

Tests the functionality of the book navigation block.

File

core/modules/book/tests/src/Functional/BookTest.php, line 270

Class

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

Namespace

Drupal\Tests\book\Functional

Code

public function testBookNavigationBlock() {
    $this->drupalLogin($this->adminUser);
    // Enable the block.
    $block = $this->drupalPlaceBlock('book_navigation');
    // Give anonymous users the permission 'node test view'.
    $edit = [];
    $edit[RoleInterface::ANONYMOUS_ID . '[node test view]'] = TRUE;
    $this->drupalPostForm('admin/people/permissions/' . RoleInterface::ANONYMOUS_ID, $edit, t('Save permissions'));
    $this->assertText(t('The changes have been saved.'), "Permission 'node test view' successfully assigned to anonymous users.");
    // Test correct display of the block.
    $nodes = $this->createBook();
    $this->drupalGet('<front>');
    $this->assertText($block->label(), 'Book navigation block is displayed.');
    $this->assertText($this->book
        ->label(), new FormattableMarkup('Link to book root (@title) is displayed.', [
        '@title' => $nodes[0]->label(),
    ]));
    $this->assertNoText($nodes[0]->label(), 'No links to individual book pages are displayed.');
}

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