File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -158,10 +158,20 @@ public function schema($field = false) {
158
158
159
159
class TestHelper extends Helper {
160
160
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
+
161
171
/**
162
172
* Helpers for this helper.
163
173
*
164
- * @var string
174
+ * @var array
165
175
*/
166
176
public $ helpers = array ('Html ' , 'TestPlugin.OtherHelper ' );
167
177
@@ -264,6 +274,24 @@ public static function entityProvider() {
264
274
);
265
275
}
266
276
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
+
267
295
/**
268
296
* Test setting an entity and retrieving the entity, model and field.
269
297
*
Original file line number Diff line number Diff line change 24
24
*/
25
25
class Helper extends Object {
26
26
27
+ /**
28
+ * Settings for this helper.
29
+ *
30
+ * @var array
31
+ */
32
+ public $ settings = array ();
33
+
27
34
/**
28
35
* List of helpers used by this helper
29
36
*
@@ -164,6 +171,9 @@ class Helper extends Object {
164
171
public function __construct (View $ View , $ settings = array ()) {
165
172
$ this ->_View = $ View ;
166
173
$ this ->request = $ View ->request ;
174
+ if ($ settings ) {
175
+ $ this ->settings = Hash::merge ($ this ->settings , $ settings );
176
+ }
167
177
if (!empty ($ this ->helpers )) {
168
178
$ this ->_helperMap = ObjectCollection::normalizeObjectArray ($ this ->helpers );
169
179
}
You can’t perform that action at this time.
0 commit comments