diff --git a/modules/book/book.module b/modules/book/book.module index 779c907..fee2467 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -282,7 +282,7 @@ function book_block_view($delta = '') { // Only display this block when the user is browsing a book. $select = db_select('node', 'n') ->fields('n', array('title')) - ->condition('nid', $node->book['bid']) + ->condition('n.nid', $node->book['bid']) ->addTag('node_access'); $title = $select->execute()->fetchField(); // Only show the block if the user has view access for the top-level node. diff --git a/modules/book/book.test b/modules/book/book.test index cc61778..1a1aac3 100644 --- a/modules/book/book.test +++ b/modules/book/book.test @@ -24,11 +24,14 @@ class BookTestCase extends DrupalWebTestCase { } function setUp() { - parent::setUp('book'); + parent::setUp(array('book', 'node_access_test')); + + // node_access_test requires a node_access_rebuild() + node_access_rebuild(); // Create users. $this->book_author = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books')); - $this->web_user = $this->drupalCreateUser(array('access printer-friendly version')); + $this->web_user = $this->drupalCreateUser(array('access printer-friendly version', 'node test view')); $this->admin_user = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books', 'administer blocks')); } @@ -281,4 +284,41 @@ class BookTestCase extends DrupalWebTestCase { $this->assertText($this->book->title, t('Link to book root (@title) is displayed.', array('@title' => $nodes[0]->title))); $this->assertNoText($nodes[0]->title, t('No links to individual book pages are displayed.')); } + + /** + * Test the functionality of the book navigation block when an access module is enabled + */ + function testNavigationBlockOnAccessModuleEnabled() { + $this->drupalLogin($this->admin_user); + $edit = array(); + + // Set the block title + $block_title = $this->randomName(16); + $edit['title'] = $block_title; + + // Set block display to 'Show block only on book pages' + $edit['book_block_mode'] = 'book pages'; + $this->drupalPost('admin/structure/block/manage/book/navigation/configure', $edit, t('Save block')); + $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.')); + + // Set the block to a region to confirm block is available + $edit = array(); + $edit['blocks[book_navigation][region]'] = 'footer'; + $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.')); + + // Create a book + $this->createBook(); + $this->drupalLogout(); + + // Test correct display of the block to registered users. + $this->drupalLogin($this->web_user); + $this->drupalGet('node/' . $this->book->nid); + $this->assertText($block_title, t('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_title, t('Book navigation block is displayed to anonymous users.')); + } }