verifyPageCache example

'label' => 'Llama',
      'description' => 'Description text',
    ]);
    $menu->save();
    /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
    $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
    // Move a link into the new menu.     $menu_link = $menu_link_manager->updateDefinition('test_page_test.test_page', ['menu_name' => 'llama', 'parent' => '']);
    $block = $this->drupalPlaceBlock('system_menu_block:llama', ['label' => 'Llama', 'provider' => 'system', 'region' => 'footer']);

    // Prime the page cache.     $this->verifyPageCache($url, 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags.     $expected_tags = [
      'http_response',
      'rendered',
      'block_view',
      'config:block_list',
      'config:block.block.' . $block->id(),
      'config:system.menu.llama',
      // The cache contexts associated with the (in)accessible menu links are       // bubbled.
// Verify a cache miss.     $this->assertFalse(\Drupal::cache('render')->get('foo'), 'Creating a new shortcut invalidates the cache tag of the shortcut set.');
  }

  /** * Tests visibility and cacheability of shortcuts in the toolbar. */
  public function testToolbar() {
    $this->drupalPlaceBlock('page_title_block', ['id' => 'title']);

    $test_page_url = Url::fromRoute('test_page_test.test_page');
    $this->verifyPageCache($test_page_url, 'MISS');
    $this->verifyPageCache($test_page_url, 'HIT');

    // Ensure that without enabling the shortcuts-in-page-title-link feature     // in the theme, the shortcut_list cache tag is not added to the page.     $this->drupalLogin($this->rootUser);
    $this->drupalGet('admin/config/system/cron');
    $expected_cache_tags = [
      'block_view',
      'config:block.block.title',
      'config:block_list',
      'config:shortcut.set.default',
      
$non_referencing_entity_cache_tags = Cache::mergeTags($non_referencing_entity_cache_tags['rendered']);

    // Generate the cache tags for all two possible entity listing paths.     // 1. list cache tag only (listing query has no match)     // 2. list cache tag plus entity cache tag (listing query has a match)     $empty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags()$page_cache_tags);

    $nonempty_entity_listing_cache_tags = Cache::mergeTags($this->entity->getEntityType()->getListCacheTags()$this->entity->getCacheTags());
    $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags$this->getAdditionalCacheTagsForEntityListing());
    $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags$page_cache_tags);

    $this->verifyPageCache($referencing_entity_url, 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags.     $expected_tags = Cache::mergeTags($referencing_entity_cache_tags$page_cache_tags);
    $expected_tags = Cache::mergeTags($expected_tags$page_cache_tags_referencing_entity);
    $this->verifyPageCache($referencing_entity_url, 'HIT', $expected_tags);

    // Also verify the existence of an entity render cache entry.     $cache_keys = ['entity_view', 'entity_test', $this->referencingEntity->id(), 'full'];
    $cid = $this->createCacheId($cache_keys$entity_cache_contexts);
    $access_cache_contexts = $this->getAccessCacheContextsForEntity($this->entity);
    $additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->referencingEntity);
    
/** * Tests cache tags presence and invalidation of the Tour entity. * * Tests the following cache tags: * - 'tour:<tour ID>' */
  public function testRenderedTour() {
    $url = Url::fromRoute('tour_test.1');

    // Prime the page cache.     $this->verifyPageCache($url, 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags.     $expected_tags = [
      'config:tour.tour.tour-test',
      'config:user.role.anonymous',
      'http_response',
      'rendered',
    ];
    $this->verifyPageCache($url, 'HIT', $expected_tags);

    // Verify that after modifying the tour, there is a cache miss.
// Selects the view mode that will be used.     $view_mode = $this->selectViewMode($entity_type);

    // The default cache contexts for rendered entities.     $entity_cache_contexts = $this->getDefaultCacheContexts();

    // Generate the standardized entity cache tags.     $cache_tag = $this->entity->getCacheTags();
    $view_cache_tag = \Drupal::entityTypeManager()->getViewBuilder($entity_type)->getCacheTags();
    $render_cache_tag = 'rendered';

    $this->verifyPageCache($entity_url, 'MISS');

    // Verify a cache hit, but also the presence of the correct cache tags.     $this->verifyPageCache($entity_url, 'HIT');

    // Also verify the existence of an entity render cache entry, if this entity     // type supports render caching.     if (\Drupal::entityTypeManager()->getDefinition($entity_type)->isRenderCacheable()) {
      $cache_keys = ['entity_view', $entity_type$this->entity->id()$view_mode];
      $cid = $this->createCacheId($cache_keys$entity_cache_contexts);
      $redirected_cid = NULL;
      $additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->entity);
      
'status' => CommentInterface::PUBLISHED,
    ]);
    $comment->save();

    return $comment;
  }

  /** * Tests that comments invalidate the cache tag of their host entity. */
  public function testCommentEntity() {
    $this->verifyPageCache($this->entityTestCamelid->toUrl(), 'MISS');
    $this->verifyPageCache($this->entityTestCamelid->toUrl(), 'HIT');

    // Create a "Hippopotamus" comment.     $this->entityTestHippopotamidae = EntityTest::create([
      'name' => 'Hippopotamus',
      'type' => 'bar',
    ]);
    $this->entityTestHippopotamidae->save();

    $this->verifyPageCache($this->entityTestHippopotamidae->toUrl(), 'MISS');
    $this->verifyPageCache($this->entityTestHippopotamidae->toUrl(), 'HIT');

    
Home | Imprint | This part of the site doesn't use cookies.