function BookTest::testNavigationBlockOnAccessModuleEnabled

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

File

drupal/core/modules/book/lib/Drupal/book/Tests/BookTest.php, line 340
Definition of Drupal\book\Tests\BookTest.

Class

BookTest
Tests the functionality of the Book module.

Namespace

Drupal\book\Tests

Code

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

  // Give anonymous users the permission 'node test view'.
  $edit = array();
  $edit[DRUPAL_ANONYMOUS_RID . '[node test view]'] = TRUE;
  $this
    ->drupalPost('admin/people/permissions/' . DRUPAL_ANONYMOUS_RID, $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->web_user);
  $this
    ->drupalGet('node/' . $this->book->nid);
  $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->nid);
  $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.');
}