public function BookTest::testHookNodeLoadAccess in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/book/src/Tests/BookTest.php \Drupal\book\Tests\BookTest::testHookNodeLoadAccess()
Ensure the loaded book in hook_node_load() does not depend on the user.
File
- core/
modules/ book/ src/ Tests/ BookTest.php, line 651 - Contains \Drupal\book\Tests\BookTest.
Class
- BookTest
- Create a book, add pages, and test book interface.
Namespace
Drupal\book\TestsCode
public function testHookNodeLoadAccess() {
\Drupal::service('module_installer')
->install([
'node_access_test',
]);
// Ensure that the loaded book in hook_node_load() does NOT depend on the
// current user.
$this
->drupalLogin($this->bookAuthor);
$this->book = $this
->createBookNode('new');
// Reset any internal static caching.
$node_storage = \Drupal::entityManager()
->getStorage('node');
$node_storage
->resetCache();
// Login as user without access to the book node, so no 'node test view'
// permission.
// @see node_access_test_node_grants().
$this
->drupalLogin($this->webUserWithoutNodeAccess);
$book_node = $node_storage
->load($this->book
->id());
$this
->assertTrue(!empty($book_node->book));
$this
->assertEqual($book_node->book['bid'], $this->book
->id());
// Reset the internal cache to retrigger the hook_node_load() call.
$node_storage
->resetCache();
$this
->drupalLogin($this->webUser);
$book_node = $node_storage
->load($this->book
->id());
$this
->assertTrue(!empty($book_node->book));
$this
->assertEqual($book_node->book['bid'], $this->book
->id());
}