Browse Source

Make View::$elementCache protected and add setter method for it.

ADmad 7 years ago
parent
commit
3b60cbeac7
2 changed files with 18 additions and 3 deletions
  1. 16 1
      src/View/View.php
  2. 2 2
      tests/TestCase/View/ViewTest.php

+ 16 - 1
src/View/View.php

@@ -225,7 +225,7 @@ class View implements EventDispatcherInterface
      * @var string
      * @see \Cake\View\View::element()
      */
-    public $elementCache = 'default';
+    protected $elementCache = 'default';
 
     /**
      * List of variables to collect from the associated controller.
@@ -1267,6 +1267,7 @@ class View implements EventDispatcherInterface
             'request' => 'setRequest',
             'response' => 'setResponse',
             'subDir' => 'setSubDir',
+            'elementCache' => 'setElementCache',
         ];
         if (isset($protected[$name])) {
             $method = $protected[$name];
@@ -1432,6 +1433,20 @@ class View implements EventDispatcherInterface
     }
 
     /**
+     * Set The cache configuration View will use to store cached elements
+     *
+     * @param string $elementCache Cache config name.
+     * @return $this
+     * @see \Cake\View\View::$elementCache
+     */
+    public function setElementCache($elementCache)
+    {
+        $this->elementCache = $elementCache;
+
+        return $this;
+    }
+
+    /**
      * Returns filename of given action's template file (.ctp) as a string.
      * CamelCased action names will be under_scored by default.
      * This means that you can have LongActionNames that refer to

+ 2 - 2
tests/TestCase/View/ViewTest.php

@@ -1034,7 +1034,7 @@ class ViewTest extends TestCase
         Cache::clear(false, 'test_view');
 
         $View = $this->PostsController->createView();
-        $View->elementCache = 'test_view';
+        $View->setElementCache('test_view');
 
         $result = $View->element('test_element', [], ['cache' => true]);
         $expected = 'this is the test element';
@@ -1058,7 +1058,7 @@ class ViewTest extends TestCase
         $result = Cache::read('element_custom_key', 'test_view');
         $this->assertEquals($expected, $result);
 
-        $View->elementCache = 'default';
+        $View->setElementCache('default');
         $View->element('test_element', [
             'param' => 'one',
             'foo' => 'two'