Added Helper::$settings

This commit is contained in:
ADmad 2012-11-30 12:11:23 +05:30
parent 1de8ed18de
commit 4a6ebaa07b
2 changed files with 39 additions and 1 deletions

View file

@ -158,10 +158,20 @@ class HelperTestPostsTag extends Model {
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 @@ class HelperTest extends CakeTestCase {
);
}
/**
* 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.
*

View file

@ -24,6 +24,13 @@ App::uses('Hash', 'Utility');
*/
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);
}