Skip to content

Commit 3885165

Browse files
committed
Merge branch 'wieseldiesel-master'
Merge fixed changes from #123 into master. Objects are now handled by makeNeatArray().
2 parents ba9af45 + a5f41ec commit 3885165

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

Test/Case/View/Helper/HtmlToolbarHelperTest.php

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @link http://cakephp.org CakePHP(tm) Project
1515
* @since DebugKit 0.1
1616
* @license http://www.opensource.org/licenses/mit-license.php MIT License
17-
**/
17+
*/
1818

1919
App::uses('View', 'View');
2020
App::uses('Controller', 'Controller');
@@ -56,7 +56,7 @@ public static function tearDownAfterClass() {
5656
* Setup
5757
*
5858
* @return void
59-
**/
59+
*/
6060
public function setUp() {
6161
parent::setUp();
6262

@@ -79,16 +79,16 @@ public function setUp() {
7979
* @return void
8080
*/
8181
public function tearDown() {
82+
parent::tearDown();
8283
unset($this->Toolbar, $this->Controller);
83-
ClassRegistry::flush();
8484
}
8585

8686
/**
87-
* Test Neat Array formatting
87+
* Test makeNeatArray with basic types.
8888
*
8989
* @return void
90-
**/
91-
public function testMakeNeatArray() {
90+
*/
91+
public function testMakeNeatArrayBasic() {
9292
$in = false;
9393
$result = $this->Toolbar->makeNeatArray($in);
9494
$expected = array(
@@ -124,7 +124,14 @@ public function testMakeNeatArray() {
124124
'/ul'
125125
);
126126
$this->assertTags($result, $expected);
127+
}
127128

129+
/**
130+
* Test Neat Array formatting
131+
*
132+
* @return void
133+
*/
134+
public function testMakeNeatArray() {
128135
$in = array('key' => 'value');
129136
$result = $this->Toolbar->makeNeatArray($in);
130137
$expected = array(
@@ -165,6 +172,7 @@ public function testMakeNeatArray() {
165172
'ul' => array('class' => 'neat-array depth-0'),
166173
'<li', '<strong', 'key', '/strong', 'value', '/li',
167174
'<li', '<strong', 'foo', '/strong',
175+
'(array)',
168176
array('ul' => array('class' => 'neat-array depth-1')),
169177
'<li', '<strong', 'this', '/strong', 'deep', '/li',
170178
'<li', '<strong', 'another', '/strong', 'value', '/li',
@@ -190,12 +198,14 @@ public function testMakeNeatArray() {
190198
'ul' => array('class' => 'neat-array depth-0 expanded'),
191199
'<li', '<strong', 'key', '/strong', 'value', '/li',
192200
'<li', '<strong', 'foo', '/strong',
201+
'(array)',
193202
array('ul' => array('class' => 'neat-array depth-1')),
194203
'<li', '<strong', 'this', '/strong', 'deep', '/li',
195204
'<li', '<strong', 'another', '/strong', 'value', '/li',
196205
'/ul',
197206
'/li',
198207
'<li', '<strong', 'lotr', '/strong',
208+
'(array)',
199209
array('ul' => array('class' => 'neat-array depth-1')),
200210
'<li', '<strong', 'gandalf', '/strong', 'wizard', '/li',
201211
'<li', '<strong', 'bilbo', '/strong', 'hobbit', '/li',
@@ -210,12 +220,14 @@ public function testMakeNeatArray() {
210220
'ul' => array('class' => 'neat-array depth-0 expanded'),
211221
'<li', '<strong', 'key', '/strong', 'value', '/li',
212222
'<li', '<strong', 'foo', '/strong',
223+
'(array)',
213224
array('ul' => array('class' => 'neat-array depth-1 expanded')),
214225
'<li', '<strong', 'this', '/strong', 'deep', '/li',
215226
'<li', '<strong', 'another', '/strong', 'value', '/li',
216227
'/ul',
217228
'/li',
218229
'<li', '<strong', 'lotr', '/strong',
230+
'(array)',
219231
array('ul' => array('class' => 'neat-array depth-1 expanded')),
220232
'<li', '<strong', 'gandalf', '/strong', 'wizard', '/li',
221233
'<li', '<strong', 'bilbo', '/strong', 'hobbit', '/li',
@@ -236,11 +248,37 @@ public function testMakeNeatArray() {
236248
$this->assertTags($result, $expected);
237249
}
238250

251+
/**
252+
* Test makeNeatArray with object inputs.
253+
*
254+
* @return void
255+
*/
256+
public function testMakeNeatArrayObjects() {
257+
$in = new StdClass();
258+
$in->key = 'value';
259+
$in->nested = new StdClass();
260+
$in->nested->name = 'mark';
261+
262+
$result = $this->Toolbar->makeNeatArray($in);
263+
$expected = array(
264+
array('ul' => array('class' => 'neat-array depth-0')),
265+
'<li', '<strong', 'key', '/strong', 'value', '/li',
266+
'<li', '<strong', 'nested', '/strong',
267+
'(object)',
268+
array('ul' => array('class' => 'neat-array depth-1')),
269+
'<li', '<strong', 'name', '/strong', 'mark', '/li',
270+
'/ul',
271+
'/li',
272+
'/ul'
273+
);
274+
$this->assertTags($result, $expected);
275+
}
276+
239277
/**
240278
* Test injection of toolbar
241279
*
242280
* @return void
243-
**/
281+
*/
244282
public function testInjectToolbar() {
245283
$this->Controller->viewPath = 'Posts';
246284
$request = new CakeRequest('/posts/index');
@@ -267,7 +305,7 @@ public function testInjectToolbar() {
267305
* test injection of javascript
268306
*
269307
* @return void
270-
**/
308+
*/
271309
public function testJavascriptInjection() {
272310
$this->Controller->viewPath = 'Posts';
273311
$this->Controller->uses = null;
@@ -336,7 +374,7 @@ public function testTable() {
336374
* test starting a panel
337375
*
338376
* @return void
339-
**/
377+
*/
340378
public function testStartPanel() {
341379
$result = $this->Toolbar->panelStart('My Panel', 'my_panel');
342380
$expected = array(
@@ -351,9 +389,10 @@ public function testStartPanel() {
351389
* test ending a panel
352390
*
353391
* @return void
354-
**/
392+
*/
355393
public function testPanelEnd() {
356394
$result = $this->Toolbar->panelEnd();
357395
$this->assertNull($result);
358396
}
397+
359398
}

View/Helper/HtmlToolbarHelper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0, $doubl
6969
}
7070
foreach ($values as $key => $value) {
7171
$out .= '<li><strong>' . $key . '</strong>';
72+
if (is_array($value) && count($value) > 0) {
73+
$out .= '(array)';
74+
} elseif (is_object($value)) {
75+
$out .= '(object)';
76+
}
7277
if ($value === null) {
7378
$value = '(null)';
7479
}
@@ -85,7 +90,7 @@ public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0, $doubl
8590
$value = 'function';
8691
}
8792

88-
if (($value instanceof ArrayAccess || $value instanceof Iterator || is_array($value)) && !empty($value)) {
93+
if (($value instanceof ArrayAccess || $value instanceof Iterator || is_array($value) || is_object($value)) && !empty($value)) {
8994
$out .= $this->makeNeatArray($value, $openDepth, $nextDepth, $doubleEncode);
9095
} else {
9196
$out .= h($value, $doubleEncode);

0 commit comments

Comments
 (0)