You are here

public function RenderCacheIntegrationTest::testBuildRenderableWithCacheContexts in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php \Drupal\Tests\views\Kernel\RenderCacheIntegrationTest::testBuildRenderableWithCacheContexts()
  2. 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 271

Class

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

Namespace

Drupal\Tests\views\Kernel

Code

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