diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index fcb46a4..859372d 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -913,7 +913,6 @@ public function bookTreeCheckAccess(&$tree, $node_links = array()) { // field language and just fall back to the default language. $nids = \Drupal::entityQuery('node') ->condition('nid', $nids, 'IN') - ->condition('status', 1) ->execute(); foreach ($nids as $nid) { diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php index b530265..6092913 100644 --- a/core/modules/book/src/Tests/BookTest.php +++ b/core/modules/book/src/Tests/BookTest.php @@ -44,14 +44,14 @@ class BookTest extends WebTestBase { /** * A user with permission to view a book and access printer-friendly version. * - * @var object + * @var \Drupal\user\UserInterface */ protected $webUser; /** * A user with permission to create and edit books and to administer blocks. * - * @var object + * @var \Drupal\user\UserInterface */ protected $adminUser; @@ -81,6 +81,8 @@ protected function setUp() { /** * Creates a new book with a page hierarchy. + * + * @return \Drupal\node\NodeInterface[] */ function createBook() { // Create new book. @@ -435,6 +437,26 @@ function testBookNavigationBlock() { $this->assertText($block->label(), 'Book navigation block is displayed.'); $this->assertText($this->book->label(), format_string('Link to book root (@title) is displayed.', array('@title' => $nodes[0]->label()))); $this->assertNoText($nodes[0]->label(), 'No links to individual book pages are displayed.'); + + // Ensure that an unpublished node does not appear in the navigation for a + // user without access. By unpublishing a parent page, child pages should + // not appear in the navigation. The node_access_test module is disabled + // since it interfers with this logic. + + /** @var \Drupal\Core\Extension\ModuleInstaller $installer */ + $installer = \Drupal::service('module_installer'); + $installer->uninstall(['node_access_test']); + node_access_rebuild(); + + $nodes[0]->setPublished(FALSE); + $nodes[0]->save(); + $this->drupalLogin($this->webUser); + $this->drupalGet($nodes[0]->urlInfo()); + $this->assertResponse(403); + $this->drupalGet($this->book->urlInfo()); + $this->assertNoText($nodes[0]->getTitle(), 'Unpublished book page does not appear in the navigation for users without access.'); + $this->assertNoText($nodes[1]->getTitle(), 'Published child page does not appear below an unpublished parent.'); + $this->assertNoText($nodes[2]->getTitle(), 'Published child page does not appear below an unpublished parent.'); } /** @@ -712,7 +734,7 @@ public function testBookListing() { */ public function testAdminBookListing() { // Create a new book. - $this->createBook(); + $nodes = $this->createBook(); // Load the book page and assert the created book title is displayed. $this->drupalLogin($this->adminUser); @@ -735,6 +757,29 @@ public function testAdminBookNodeListing() { $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a'); $this->assertEqual((string) $elements[0], 'View', 'View link is found from the list.'); + $this->assertEqual(count($nodes), count($elements), 'All the book pages are displayed on the book outline page.'); + + // Unpublish a book in the hierarchy. + $nodes[0]->setPublished(FALSE); + $nodes[0]->save(); + + // Node should still appear on the outline for admins. + $this->drupalGet('admin/structure/book/' . $this->book->id()); + $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a'); + $this->assertEqual(count($nodes), count($elements), 'All the book pages are displayed on the book outline page.'); + + // Saving a book page not as the current version shouldn't effect the book. + $old_title = $nodes[1]->getTitle(); + $new_title = $this->randomGenerator->name(); + $nodes[1]->isDefaultRevision(FALSE); + $nodes[1]->setNewRevision(TRUE); + $nodes[1]->setTitle($new_title); + $nodes[1]->save(); + $this->drupalGet('admin/structure/book/' . $this->book->id()); + $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a'); + $this->assertEqual(count($nodes), count($elements), 'All the book pages are displayed on the book outline page.'); + $this->assertNoText($new_title, 'The revision that is not the default revision does not appear.'); + $this->assertText($old_title, 'The default revision title appears.'); } /**