public function BookTest::testBookNavigationCacheContext in Drupal 10
Same name and namespace in other branches
- 8 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookNavigationCacheContext()
- 9 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookNavigationCacheContext()
Tests the book navigation cache context.
See also
\Drupal\book\Cache\BookNavigationCacheContext
File
- core/
modules/ book/ tests/ src/ Functional/ BookTest.php, line 104
Class
- BookTest
- Create a book, add pages, and test book interface.
Namespace
Drupal\Tests\book\FunctionalCode
public function testBookNavigationCacheContext() {
// Create a page node.
$this
->drupalCreateContentType([
'type' => 'page',
]);
$page = $this
->drupalCreateNode();
// Create a book, consisting of book nodes.
$book_nodes = $this
->createBook();
// Enable the debug output.
\Drupal::state()
->set('book_test.debug_book_navigation_cache_context', TRUE);
Cache::invalidateTags([
'book_test.debug_book_navigation_cache_context',
]);
$this
->drupalLogin($this->bookAuthor);
// On non-node route.
$this
->drupalGet($this->adminUser
->toUrl());
$this
->assertSession()
->responseContains('[route.book_navigation]=book.none');
// On non-book node route.
$this
->drupalGet($page
->toUrl());
$this
->assertSession()
->responseContains('[route.book_navigation]=book.none');
// On book node route.
$this
->drupalGet($book_nodes[0]
->toUrl());
$this
->assertSession()
->responseContains('[route.book_navigation]=0|2|3');
$this
->drupalGet($book_nodes[1]
->toUrl());
$this
->assertSession()
->responseContains('[route.book_navigation]=0|2|3|4');
$this
->drupalGet($book_nodes[2]
->toUrl());
$this
->assertSession()
->responseContains('[route.book_navigation]=0|2|3|5');
$this
->drupalGet($book_nodes[3]
->toUrl());
$this
->assertSession()
->responseContains('[route.book_navigation]=0|2|6');
$this
->drupalGet($book_nodes[4]
->toUrl());
$this
->assertSession()
->responseContains('[route.book_navigation]=0|2|7');
}