function BookTest::testBookNavigationBlockOnUnpublishedBook

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

Tests the book navigation block when book is unpublished.

There was a fatal error with "Show block only on book pages" block mode.

File

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

Class

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

Namespace

Drupal\Tests\book\Functional

Code

public function testBookNavigationBlockOnUnpublishedBook() {
    // Create a new book.
    $this->createBook();
    // Create administrator user.
    $administratorUser = $this->drupalCreateUser([
        'administer blocks',
        'administer nodes',
        'bypass node access',
    ]);
    $this->drupalLogin($administratorUser);
    // Enable the block with "Show block only on book pages" mode.
    $this->drupalPlaceBlock('book_navigation', [
        'block_mode' => 'book pages',
    ]);
    // Unpublish book node.
    $edit = [
        'status[value]' => FALSE,
    ];
    $this->drupalGet('node/' . $this->book
        ->id() . '/edit');
    $this->submitForm($edit, 'Save');
    // Test node page.
    $this->drupalGet('node/' . $this->book
        ->id());
    // Unpublished book with "Show block only on book pages" book navigation
    // settings.
    $this->assertSession()
        ->pageTextContains($this->book
        ->label());
}

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