Commit 8a5cc902 authored by alexpott's avatar alexpott

Issue #2708485 by damiankloip: Views Row caching still caches rows when cache plugin is 'none'

parent 376591ed
......@@ -678,6 +678,7 @@ protected function renderFields(array $result) {
$renderer = $this->getRenderer();
/** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
$cache_plugin = $this->view->display_handler->getPlugin('cache');
$max_age = $cache_plugin->getCacheMaxAge();
/** @var \Drupal\views\ResultRow $row */
foreach ($result as $index => $row) {
......@@ -698,6 +699,7 @@ protected function renderFields(array $result) {
'#cache' => [
'keys' => $cache_plugin->getRowCacheKeys($row),
'tags' => $cache_plugin->getRowCacheTags($row),
'max-age' => $max_age,
],
'#cache_properties' => $field_ids,
];
......
......@@ -31,7 +31,7 @@ class RowRenderCacheTest extends ViewsKernelTestBase {
*
* @var array
*/
public static $testViews = array('test_row_render_cache');
public static $testViews = array('test_row_render_cache', 'test_row_render_cache_none');
/**
* An editor user account.
......@@ -103,6 +103,34 @@ public function testAdvancedCaching() {
$this->doTestRenderedOutput($this->editorUser);
}
/**
* Test that rows are not cached when the none cache plugin is used.
*/
public function testNoCaching() {
$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);
}
}
/**
* Check whether the rendered output matches expectations.
*
......@@ -161,7 +189,13 @@ protected function doTestRenderedOutput(AccountInterface $account, $check_cache
if ($check_cache) {
$keys = $cache_plugin->getRowCacheKeys($view->result[$index]);
$user_context = !$account->hasPermission('edit any test content') ? 'user' : 'user.permissions';
$element = $render_cache->get(['#cache' => ['keys' => $keys, 'contexts' => ['languages:language_interface', 'theme', $user_context]]]);
$cache = [
'#cache' => [
'keys' => $keys,
'contexts' => ['languages:language_interface', 'theme', $user_context],
],
];
$element = $render_cache->get($cache);
$this->assertTrue($element);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment