function RowRenderCacheTest::testNoCaching

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/RowRenderCacheTest.php \Drupal\Tests\views\Kernel\Plugin\RowRenderCacheTest::testNoCaching()
  2. 8.9.x core/modules/views/tests/src/Kernel/Plugin/RowRenderCacheTest.php \Drupal\Tests\views\Kernel\Plugin\RowRenderCacheTest::testNoCaching()
  3. 11.x core/modules/views/tests/src/Kernel/Plugin/RowRenderCacheTest.php \Drupal\Tests\views\Kernel\Plugin\RowRenderCacheTest::testNoCaching()

Tests that rows are not cached when the none cache plugin is used.

File

core/modules/views/tests/src/Kernel/Plugin/RowRenderCacheTest.php, line 113

Class

RowRenderCacheTest
Tests row render caching.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testNoCaching() : void {
    $this->setCurrentUser($this->regularUser);
    $view = Views::getView('test_row_render_cache_none');
    $view->setDisplay();
    $view->preview();
    
    /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
    $render_cache = $this->container
        ->get('render_cache');
    
    /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
    $cache_plugin = $view->display_handler
        ->getPlugin('cache');
    foreach ($view->result as $row) {
        $keys = $cache_plugin->getRowCacheKeys($row);
        $cache = [
            '#cache' => [
                'keys' => $keys,
                'contexts' => [
                    'languages:language_interface',
                    'theme',
                    'user.permissions',
                ],
            ],
        ];
        $element = $render_cache->get($cache);
        $this->assertFalse($element);
    }
}

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