function RenderCacheIntegrationTest::testBuildRenderableWithCacheContexts

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

Ensure that the view renderable contains the cache contexts.

File

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

Class

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

Namespace

Drupal\Tests\views\Kernel

Code

public function testBuildRenderableWithCacheContexts() : void {
    $view = View::load('test_view');
    $display =& $view->getDisplay('default');
    $display['cache_metadata']['contexts'] = [
        'views_test_cache_context',
    ];
    $executable = $view->getExecutable();
    $build = $executable->buildRenderable();
    $this->assertEquals([
        'views_test_cache_context',
    ], $build['#cache']['contexts']);
}

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