Fix unit tests breaking with v5

This commit is contained in:
Chris Lock 2023-07-03 00:00:33 +01:00
parent 628d4cb96e
commit d61b86fd3d

View File

@ -386,26 +386,22 @@ class GridFieldOrderableRows extends RequestHandler implements
$sortterm = $this->extraSortFields . ', '; $sortterm = $this->extraSortFields . ', ';
} }
} }
if ($list instanceof ArrayList) {
// Fix bug in 3.1.3+ where ArrayList doesn't account for quotes
$sortterm .= $this->getSortTable($list) . '.' . $this->getSortField();
} else {
$sortterm .= '"' . $this->getSortTable($list) . '"."' . $this->getSortField() . '"';
if ($list instanceof DataList) { $sortterm .= '"' . $this->getSortField() . '"';
$classname = $list->dataClass();
if ($defaultSort = Config::inst()->get($classname, 'default_sort')) { if ($list instanceof DataList) {
if (is_array($defaultSort)) { $classname = $list->dataClass();
$defaultSortArray = []; if ($defaultSort = Config::inst()->get($classname, 'default_sort')) {
foreach ($defaultSort as $column => $direction) { if (is_array($defaultSort)) {
$defaultSortArray[] = "\"$column\" $direction"; $defaultSortArray = [];
} foreach ($defaultSort as $column => $direction) {
$defaultSort = implode(', ', $defaultSortArray); $defaultSortArray[] = "\"$column\" $direction";
} }
// Append the default sort to the end of the sort string $defaultSort = implode(', ', $defaultSortArray);
// This may result in redundancy... but it seems to work
$sortterm .= ($sortterm ? ', ' : '') . $defaultSort;
} }
// Append the default sort to the end of the sort string
// This may result in redundancy... but it seems to work
$sortterm .= ($sortterm ? ', ' : '') . $defaultSort;
} }
} }
@ -468,10 +464,10 @@ class GridFieldOrderableRows extends RequestHandler implements
protected function getSortedIDs($data) protected function getSortedIDs($data)
{ {
if (empty($data['GridFieldEditableColumns'])) { if (empty($data['GridFieldEditableColumns'])) {
return array(); return [];
} }
$sortedIDs = array(); $sortedIDs = [];
foreach ($data['GridFieldEditableColumns'] as $id => $recordData) { foreach ($data['GridFieldEditableColumns'] as $id => $recordData) {
$sortValue = $recordData[$this->sortField]; $sortValue = $recordData[$this->sortField];
$sortedIDs[$sortValue] = $id; $sortedIDs[$sortValue] = $id;
@ -582,7 +578,8 @@ class GridFieldOrderableRows extends RequestHandler implements
} }
} }
$list = $grid->getList(); $list = $grid->getList();
$sortterm .= '"' . $this->getSortTable($list) . '"."' . $sortField . '"'; $sortterm .= '"' . $sortField . '"';
$items = $list->filter('ID', $sortedIDs)->sort($sortterm); $items = $list->filter('ID', $sortedIDs)->sort($sortterm);
// Ensure that each provided ID corresponded to an actual object. // Ensure that each provided ID corresponded to an actual object.