You are here

public function BookTest::testNavigationBlockOnAccessModuleInstalled in Drupal 9

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

Tests the book navigation block when an access module is installed.

File

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

Class

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

Namespace

Drupal\Tests\book\Functional

Code

public function testNavigationBlockOnAccessModuleInstalled() {
  $this
    ->drupalLogin($this->adminUser);
  $block = $this
    ->drupalPlaceBlock('book_navigation', [
    'block_mode' => 'book pages',
  ]);

  // Give anonymous users the permission 'node test view'.
  $edit = [];
  $edit[RoleInterface::ANONYMOUS_ID . '[node test view]'] = TRUE;
  $this
    ->drupalGet('admin/people/permissions/' . RoleInterface::ANONYMOUS_ID);
  $this
    ->submitForm($edit, 'Save permissions');
  $this
    ->assertSession()
    ->pageTextContains('The changes have been saved.');

  // Create a book.
  $this
    ->createBook();

  // Test correct display of the block to registered users.
  $this
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet('node/' . $this->book
    ->id());
  $this
    ->assertSession()
    ->pageTextContains($block
    ->label());
  $this
    ->drupalLogout();

  // Test correct display of the block to anonymous users.
  $this
    ->drupalGet('node/' . $this->book
    ->id());
  $this
    ->assertSession()
    ->pageTextContains($block
    ->label());

  // Test the 'book pages' block_mode setting.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->pageTextNotContains($block
    ->label());
}