function RenderCacheIntegrationTest::assertCacheTagsForEntityBasedView

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php \Drupal\Tests\views\Kernel\RenderCacheIntegrationTest::assertCacheTagsForEntityBasedView()
  2. 10 core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php \Drupal\Tests\views\Kernel\RenderCacheIntegrationTest::assertCacheTagsForEntityBasedView()
  3. 11.x core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php \Drupal\Tests\views\Kernel\RenderCacheIntegrationTest::assertCacheTagsForEntityBasedView()

Tests cache tags on output & result cache items for an entity-based view.

@internal

3 calls to RenderCacheIntegrationTest::assertCacheTagsForEntityBasedView()
RenderCacheIntegrationTest::testEntityBasedViewCacheTagsWithCachePluginNone in core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php
Tests an entity-based view's cache tags when using the "none" cache plugin.
RenderCacheIntegrationTest::testEntityBasedViewCacheTagsWithCachePluginTag in core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php
Tests an entity-based view's cache tags when using the "tag" cache plugin.
RenderCacheIntegrationTest::testEntityBasedViewCacheTagsWithCachePluginTime in core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php
Tests an entity-based view's cache tags when using the "time" cache plugin.

File

core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php, line 237

Class

RenderCacheIntegrationTest
Tests the general integration between views and the render cache.

Namespace

Drupal\Tests\views\Kernel

Code

protected function assertCacheTagsForEntityBasedView(bool $do_assert_views_caches) : void {
    $view = Views::getview('entity_test_row');
    // Empty result (no entities yet).
    $base_tags = $base_render_tags = [
        'config:views.view.entity_test_row',
        'entity_test_list',
    ];
    $this->assertViewsCacheTags($view, $base_tags, $do_assert_views_caches, $base_tags);
    $this->assertViewsCacheTagsFromStaticRenderArray($view, $base_tags, $do_assert_views_caches);
    // Non-empty result (1 entity).
    $entities[] = $entity = EntityTest::create();
    $entity->save();
    $result_tags_with_entity = Cache::mergeTags($base_tags, $entities[0]->getCacheTags());
    $render_tags_with_entity = Cache::mergeTags($base_render_tags, $entities[0]->getCacheTags());
    $render_tags_with_entity = Cache::mergeTags($render_tags_with_entity, [
        'entity_test_view',
    ]);
    $this->assertViewsCacheTags($view, $result_tags_with_entity, $do_assert_views_caches, $render_tags_with_entity);
    $this->assertViewsCacheTagsFromStaticRenderArray($view, $render_tags_with_entity, $do_assert_views_caches);
    // Paged result (more entities than the items-per-page limit).
    for ($i = 0; $i < 5; $i++) {
        $entities[] = $entity = EntityTest::create();
        $entity->save();
    }
    $new_entities_cache_tags = Cache::mergeTags($entities[1]->getCacheTags(), $entities[2]->getCacheTags());
    $new_entities_cache_tags = Cache::mergeTags($new_entities_cache_tags, $entities[3]->getCacheTags());
    $new_entities_cache_tags = Cache::mergeTags($new_entities_cache_tags, $entities[4]->getCacheTags());
    $new_entities_cache_tags = Cache::mergeTags($new_entities_cache_tags, $entities[5]->getCacheTags());
    $result_tags_page_1 = Cache::mergeTags($base_tags, $new_entities_cache_tags);
    $render_tags_page_1 = Cache::mergeTags($base_render_tags, $new_entities_cache_tags);
    $render_tags_page_1 = Cache::mergeTags($render_tags_page_1, [
        'entity_test_view',
    ]);
    $this->assertViewsCacheTags($view, $result_tags_page_1, $do_assert_views_caches, $render_tags_page_1);
    $this->assertViewsCacheTagsFromStaticRenderArray($view, $render_tags_page_1, $do_assert_views_caches);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.