From 3574e670fe6e6f3f3639d890c3067a8571e62f0b Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Wed, 1 Jan 2014 20:37:54 +0000
Subject: [PATCH] Issue #1987236 by dawehner, kalabro: [regression] Views block
 cache setting doesn't work.

---
 .../Drupal/block/Tests/Views/DisplayBlockTest.php   | 13 +++++++++++++
 .../test_views/views.view.test_view_block2.yml      | 10 ++++++++++
 .../lib/Drupal/views/Plugin/Block/ViewsBlock.php    |  5 +++++
 3 files changed, 28 insertions(+)

diff --git a/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php
index fd9d254717f5..1cee4b806a37 100644
--- a/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php
@@ -174,6 +174,19 @@ protected function testDeleteBlockDisplay() {
     $this->assertBlockAppears($block_4);
   }
 
+  /**
+   * Tests views block plugin definitions.
+   */
+  public function testViewsBlockPlugins() {
+    // Ensures that the cache setting gets to the block settings.
+    $instance = $this->container->get('plugin.manager.block')->createInstance('views_block:test_view_block2-block_2');
+    $configuration = $instance->getConfiguration();
+    $this->assertEqual($configuration['cache'], DRUPAL_NO_CACHE);
+    $instance = $this->container->get('plugin.manager.block')->createInstance('views_block:test_view_block2-block_3');
+    $configuration = $instance->getConfiguration();
+    $this->assertEqual($configuration['cache'], DRUPAL_CACHE_PER_USER);
+  }
+
   /**
    * Test the block form for a Views block.
    */
diff --git a/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block2.yml b/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block2.yml
index e693732ba5b9..9b71048c4927 100644
--- a/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block2.yml
+++ b/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block2.yml
@@ -51,6 +51,16 @@ display:
       field:
         title:
           link_to_node: '1'
+  block_3:
+    display_plugin: block
+    id: block_3
+    display_title: Block
+    position: ''
+    display_options:
+      block_caching: '2'
+      field:
+        title:
+          link_to_node: '1'
 label: test_view_block2
 module: views
 id: test_view_block2
diff --git a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php
index 4d521a9c9b3a..0804b55b50b7 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php
@@ -56,6 +56,11 @@ public function defaultConfiguration() {
       $settings += $this->view->display_handler->blockSettings($settings);
     }
 
+    // Set custom cache settings.
+    if (isset($this->pluginDefinition['cache'])) {
+      $settings['cache'] = $this->pluginDefinition['cache'];
+    }
+
     return $settings;
   }
 
-- 
GitLab