function BookTest::testNavigationBlockOnAccessModuleInstalled

Same name in other branches
  1. 9 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testNavigationBlockOnAccessModuleInstalled()
  2. 8.9.x core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testNavigationBlockOnAccessModuleInstalled()
  3. 11.x 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 387

Class

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

Namespace

Drupal\Tests\book\Functional

Code

public function testNavigationBlockOnAccessModuleInstalled() : void {
    $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());
}

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