Skip to content

Commit 10c2457

Browse files
committed
Fix sorting and collapsing of dump output
I thought the panel layout was used. It is not. I forgot to apply variable sorting when switching dump implementations. Fixes #771
1 parent 98eba19 commit 10c2457

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

src/View/Helper/ToolbarHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function dump($value)
7272
$restore = true;
7373
$debugger->setConfig('exportFormatter', HtmlFormatter::class);
7474
}
75+
76+
if ($this->sort && is_array($value)) {
77+
ksort($value);
78+
}
79+
7580
$contents = Debugger::exportVar($value, 25);
7681
if ($restore) {
7782
$debugger->setConfig('exportFormatter', $exportFormatter);

templates/layout/panel.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/TestCase/View/Helper/ToolbarHelperTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Cake\View\View;
2424
use DebugKit\View\Helper\ToolbarHelper;
2525
use stdClass;
26+
use SimpleXmlElement;
2627

2728
/**
2829
* Class ToolbarHelperTestCase
@@ -78,10 +79,30 @@ public function testDumpCoerceHtml()
7879
Debugger::configInstance('exportFormatter'),
7980
'Should restore setting'
8081
);
82+
8183
// Restore back to original value.
8284
Debugger::configInstance('exportFormatter', $restore);
8385
}
8486

87+
public function testDumpSorted()
88+
{
89+
$getValues = function ($el) {
90+
return (string)$el;
91+
};
92+
$path = '//*[@class="cake-dbg-array-item"]/*[@class="cake-dbg-string"]';
93+
$data = ['z' => 1, 'a' => 99, 'm' => 123];
94+
$result = $this->Toolbar->dump($data);
95+
$xml = new SimpleXmlElement($result);
96+
$elements = $xml->xpath($path);
97+
$this->assertSame(["'z'", "'a'", "'m'"], array_map($getValues, $elements));
98+
99+
$this->Toolbar->setSort(true);
100+
$result = $this->Toolbar->dump($data);
101+
$xml = new SimpleXmlElement($result);
102+
$elements = $xml->xpath($path);
103+
$this->assertSame(["'a'", "'m'", "'z'"], array_map($getValues, $elements));
104+
}
105+
85106
/**
86107
* Test makeNeatArray with basic types.
87108
*

webroot/js/toolbar-app.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ Toolbar.prototype = {
150150
// Slide panel into place - css transitions.
151151
_this.content.addClass('enabled');
152152
contentArea.html(response);
153+
_this.bindVariableSort();
154+
_this.bindDebugBlock();
155+
153156
_this.bindNeatArray();
154157
});
155158
},
156159

157-
bindNeatArray: function() {
160+
bindVariableSort: function() {
158161
var sortButton = this.content.find('.neat-array-sort');
159162
var _this = this;
160163
sortButton.click(function() {
@@ -165,7 +168,16 @@ Toolbar.prototype = {
165168
}
166169
_this.loadPanel(_this.currentPanel());
167170
});
171+
},
172+
173+
bindDebugBlock: function () {
174+
if (window.__cakeDebugBlockInit) {
175+
window.__cakeDebugBlockInit();
176+
}
177+
},
168178

179+
bindNeatArray: function() {
180+
var _this = this;
169181
var lists = this.content.find('.depth-0');
170182
lists.find('ul').hide()
171183
.parent().addClass('expandable collapsed');

0 commit comments

Comments
 (0)