From 4a6ebaa07b9d94fdc51f990169d7871e1b38c612 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 30 Nov 2012 12:11:23 +0530 Subject: [PATCH] Added Helper::$settings --- lib/Cake/Test/Case/View/HelperTest.php | 30 +++++++++++++++++++++++++- lib/Cake/View/Helper.php | 10 +++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index 6cecf1ea1d4..30a43d07879 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -158,10 +158,20 @@ public function schema($field = false) { class TestHelper extends Helper { +/** + * Settings for this helper. + * + * @var array + */ + public $settings = array( + 'key1' => 'val1', + 'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'val2.2') + ); + /** * Helpers for this helper. * - * @var string + * @var array */ public $helpers = array('Html', 'TestPlugin.OtherHelper'); @@ -264,6 +274,24 @@ public static function entityProvider() { ); } +/** + * Test settings merging + * + * @return void + */ + public function testSettingsMerging() { + $Helper = new TestHelper($this->View, array( + 'key3' => 'val3', + 'key2' => array('key2.2' => 'newval') + )); + $expected = array( + 'key1' => 'val1', + 'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'newval'), + 'key3' => 'val3' + ); + $this->assertEquals($expected, $Helper->settings); + } + /** * Test setting an entity and retrieving the entity, model and field. * diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index c6cd208c6ee..0b8f5398e5f 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -24,6 +24,13 @@ */ class Helper extends Object { +/** + * Settings for this helper. + * + * @var array + */ + public $settings = array(); + /** * List of helpers used by this helper * @@ -164,6 +171,9 @@ class Helper extends Object { public function __construct(View $View, $settings = array()) { $this->_View = $View; $this->request = $View->request; + if ($settings) { + $this->settings = Hash::merge($this->settings, $settings); + } if (!empty($this->helpers)) { $this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers); }