Skip to content

Commit

Permalink
Added Helper::$settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Nov 30, 2012
1 parent 1de8ed1 commit 4a6ebaa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/Cake/Test/Case/View/HelperTest.php
Expand Up @@ -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');

Expand Down Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions lib/Cake/View/Helper.php
Expand Up @@ -24,6 +24,13 @@
*/
class Helper extends Object {

/**
* Settings for this helper.
*
* @var array
*/
public $settings = array();

/**
* List of helpers used by this helper
*
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 4a6ebaa

Please sign in to comment.