function BookTest::testBookNavigationBlockOnUnpublishedBook

Same name and namespace in other branches
  1. 9 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 623

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->drupalPostForm('node/' . $this->book
        ->id() . '/edit', $edit, t('Save'));
    // Test node page.
    $this->drupalGet('node/' . $this->book
        ->id());
    $this->assertText($this->book
        ->label(), 'Unpublished book with "Show block only on book pages" book navigation settings.');
}

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