You are here

public function BookTest::testBookNavigationCacheContext in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/book/src/Tests/BookTest.php \Drupal\book\Tests\BookTest::testBookNavigationCacheContext()

Tests the book navigation cache context.

See also

\Drupal\book\Cache\BookNavigationCacheContext

File

core/modules/book/src/Tests/BookTest.php, line 119
Contains \Drupal\book\Tests\BookTest.

Class

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

Namespace

Drupal\book\Tests

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

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

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