Sorting: Fixes during testing of sort rules

- Fixed name numeric sorting not working as expected due to bad
  comparison.
- Added name numeric desc operation option.
- Added test to ensure each operating has a comparison function.
This commit is contained in:
Dan Brown
2025-02-24 16:58:59 +00:00
parent d7ccb3ce6a
commit dca14feaaa
3 changed files with 20 additions and 5 deletions

View File

@ -5,6 +5,7 @@ namespace Tests\Sorting;
use BookStack\Activity\ActivityType;
use BookStack\Entities\Models\Book;
use BookStack\Sorting\SortRule;
use BookStack\Sorting\SortRuleOperation;
use Tests\Api\TestsApi;
use Tests\TestCase;
@ -202,7 +203,8 @@ class SortRuleTest extends TestCase
"20 - Milk",
];
foreach ($namesToAdd as $name) {
$reverseNamesToAdd = array_reverse($namesToAdd);
foreach ($reverseNamesToAdd as $name) {
$this->actingAsApiEditor()->post("/api/pages", [
'book_id' => $book->id,
'name' => $name,
@ -218,4 +220,14 @@ class SortRuleTest extends TestCase
]);
}
}
public function test_each_sort_rule_operation_has_a_comparison_function()
{
$operations = SortRuleOperation::cases();
foreach ($operations as $operation) {
$comparisonFunc = $operation->getSortFunction();
$this->assertIsCallable($comparisonFunc);
}
}
}