You are here

function BookTest::testNavigationBlockOnAccessModuleInstalled in Zircon Profile 8.0

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

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

File

core/modules/book/src/Tests/BookTest.php, line 444
Contains \Drupal\book\Tests\BookTest.

Class

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

Namespace

Drupal\book\Tests

Code

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

  // Give anonymous users the permission 'node test view'.
  $edit = array();
  $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.");

  // 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
    ->assertText($block
    ->label(), 'Book navigation block is displayed to registered users.');
  $this
    ->drupalLogout();

  // Test correct display of the block to anonymous users.
  $this
    ->drupalGet('node/' . $this->book
    ->id());
  $this
    ->assertText($block
    ->label(), 'Book navigation block is displayed to anonymous users.');

  // Test the 'book pages' block_mode setting.
  $this
    ->drupalGet('<front>');
  $this
    ->assertNoText($block
    ->label(), 'Book navigation block is not shown on non-book pages.');
}