Skip to content

Commit 4a6ebaa

Browse files
committed
Added Helper::$settings
1 parent 1de8ed1 commit 4a6ebaa

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/Cake/Test/Case/View/HelperTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,20 @@ public function schema($field = false) {
158158

159159
class TestHelper extends Helper {
160160

161+
/**
162+
* Settings for this helper.
163+
*
164+
* @var array
165+
*/
166+
public $settings = array(
167+
'key1' => 'val1',
168+
'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'val2.2')
169+
);
170+
161171
/**
162172
* Helpers for this helper.
163173
*
164-
* @var string
174+
* @var array
165175
*/
166176
public $helpers = array('Html', 'TestPlugin.OtherHelper');
167177

@@ -264,6 +274,24 @@ public static function entityProvider() {
264274
);
265275
}
266276

277+
/**
278+
* Test settings merging
279+
*
280+
* @return void
281+
*/
282+
public function testSettingsMerging() {
283+
$Helper = new TestHelper($this->View, array(
284+
'key3' => 'val3',
285+
'key2' => array('key2.2' => 'newval')
286+
));
287+
$expected = array(
288+
'key1' => 'val1',
289+
'key2' => array('key2.1' => 'val2.1', 'key2.2' => 'newval'),
290+
'key3' => 'val3'
291+
);
292+
$this->assertEquals($expected, $Helper->settings);
293+
}
294+
267295
/**
268296
* Test setting an entity and retrieving the entity, model and field.
269297
*

lib/Cake/View/Helper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
*/
2525
class Helper extends Object {
2626

27+
/**
28+
* Settings for this helper.
29+
*
30+
* @var array
31+
*/
32+
public $settings = array();
33+
2734
/**
2835
* List of helpers used by this helper
2936
*
@@ -164,6 +171,9 @@ class Helper extends Object {
164171
public function __construct(View $View, $settings = array()) {
165172
$this->_View = $View;
166173
$this->request = $View->request;
174+
if ($settings) {
175+
$this->settings = Hash::merge($this->settings, $settings);
176+
}
167177
if (!empty($this->helpers)) {
168178
$this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers);
169179
}

0 commit comments

Comments
 (0)