You are here

public function BookTest::testBookNavigationCacheContext in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/book/tests/src/Functional/BookTest.php \Drupal\Tests\book\Functional\BookTest::testBookNavigationCacheContext()
  2. 10 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 105

Class

BookTest
Create a book, add pages, and test book interface.

Namespace

Drupal\Tests\book\Functional

Code

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
    ->assertRaw('[route.book_navigation]=book.none');

  // On non-book node route.
  $this
    ->drupalGet($page
    ->toUrl());
  $this
    ->assertRaw('[route.book_navigation]=book.none');

  // On book node route.
  $this
    ->drupalGet($book_nodes[0]
    ->toUrl());
  $this
    ->assertRaw('[route.book_navigation]=0|2|3');
  $this
    ->drupalGet($book_nodes[1]
    ->toUrl());
  $this
    ->assertRaw('[route.book_navigation]=0|2|3|4');
  $this
    ->drupalGet($book_nodes[2]
    ->toUrl());
  $this
    ->assertRaw('[route.book_navigation]=0|2|3|5');
  $this
    ->drupalGet($book_nodes[3]
    ->toUrl());
  $this
    ->assertRaw('[route.book_navigation]=0|2|6');
  $this
    ->drupalGet($book_nodes[4]
    ->toUrl());
  $this
    ->assertRaw('[route.book_navigation]=0|2|7');
}