From 7e1c51c2729c99229563d63580a76e88daaed922 Mon Sep 17 00:00:00 2001 From: foolfitz Date: Mon, 12 Oct 2026 23:15:35 +0800 Subject: [PATCH] fix(views): return column IDs from getColumnsArray() Use getId() instead of array_column() to read column IDs. Keep IDs sorted by order and add unit tests. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: foolfitz --- lib/Db/View.php | 2 +- tests/unit/Db/ViewTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/Db/View.php b/lib/Db/View.php index 910cf0b211..70c2c24036 100644 --- a/lib/Db/View.php +++ b/lib/Db/View.php @@ -150,7 +150,7 @@ public function getColumnsArray(): array { $columnSettings = $this->getColumnsSettingsArray(); usort($columnSettings, static fn (ViewColumnInformation $a, ViewColumnInformation $b) => $a->getOrder() - $b->getOrder()); - return array_column($columnSettings, ViewColumnInformation::KEY_ID); + return array_map(static fn (ViewColumnInformation $column): int => $column->getId(), $columnSettings); } /** diff --git a/tests/unit/Db/ViewTest.php b/tests/unit/Db/ViewTest.php index 3860de4e7e..0931443610 100644 --- a/tests/unit/Db/ViewTest.php +++ b/tests/unit/Db/ViewTest.php @@ -70,4 +70,37 @@ public static function provideUnusableViewSettings(): array { 'sources of the wrong type' => ['{"cardBackgroundSource":"3","cardTitleSource":[]}'], ]; } + + private function makeView(string $columns): View { + $view = new View(); + $view->setColumns($columns); + return $view; + } + + public function testGetColumnsArrayEmptyReturnsEmpty(): void { + $view = $this->makeView(''); + $this->assertSame([], $view->getColumnsArray()); + } + + public function testGetColumnsArrayLegacyPlainIdFormat(): void { + // Legacy format: plain array of integer column IDs — order is derived from index + $view = $this->makeView(\json_encode([10, 20, 30])); + $this->assertSame([10, 20, 30], $view->getColumnsArray()); + } + + public function testGetColumnsArrayObjectFormatIsSortedByOrder(): void { + $view = $this->makeView(\json_encode([ + ['columnId' => 5, 'order' => 2, 'readonly' => false, 'mandatory' => false], + ['columnId' => 3, 'order' => 1, 'readonly' => false, 'mandatory' => false], + ])); + $this->assertSame([3, 5], $view->getColumnsArray()); + } + + public function testJsonSerializeReturnsColumnIds(): void { + $view = $this->makeView(\json_encode([ + ['columnId' => 5, 'order' => 2, 'readonly' => false, 'mandatory' => false], + ['columnId' => 3, 'order' => 1, 'readonly' => false, 'mandatory' => false], + ])); + $this->assertSame([3, 5], $view->jsonSerialize()['columns']); + } }