]> BookStack Code Mirror - bookstack/commitdiff
Roles: fixed error upon created_at sorting
authorDan Brown <redacted>
Tue, 4 Jul 2023 20:52:46 +0000 (21:52 +0100)
committerDan Brown <redacted>
Tue, 4 Jul 2023 20:52:46 +0000 (21:52 +0100)
Added test to cover core role sorting functionality.
For #4350

app/Users/Queries/RolesAllPaginatedAndSorted.php
tests/User/RoleManagementTest.php

index 7fd4048dfca44f53a4edd47e303db90dd7389c33..c9602ee710873c7631157d2554d146d7e936abcc 100644 (file)
@@ -15,7 +15,7 @@ class RolesAllPaginatedAndSorted
     {
         $sort = $listOptions->getSort();
         if ($sort === 'created_at') {
-            $sort = 'users.created_at';
+            $sort = 'roles.created_at';
         }
 
         $query = Role::query()->select(['*'])
index 4d61cf6e6bb313b455a0bb3cc5afcb1f8a7c5689..5722a0b08c8363a064f0bd49e19dae3f82ae8611 100644 (file)
@@ -260,4 +260,30 @@ class RoleManagementTest extends TestCase
 
         $this->actingAs($viewer)->get($page->getUrl())->assertStatus(404);
     }
+
+    public function test_index_listing_sorting()
+    {
+        $this->asAdmin();
+        $role = $this->users->createRole();
+        $role->display_name = 'zz test role';
+        $role->created_at = now()->addDays(1);
+        $role->save();
+
+        $runTest = function (string $order, string $direction, bool $expectFirstResult) use ($role) {
+            setting()->putForCurrentUser('roles_sort', $order);
+            setting()->putForCurrentUser('roles_sort_order', $direction);
+            $html = $this->withHtml($this->get('/settings/roles'));
+            $selector = ".item-list-row:first-child a[href$=\"/roles/{$role->id}\"]";
+            if ($expectFirstResult) {
+                $html->assertElementExists($selector);
+            } else {
+                $html->assertElementNotExists($selector);
+            }
+        };
+
+        $runTest('name', 'asc', false);
+        $runTest('name', 'desc', true);
+        $runTest('created_at', 'desc', true);
+        $runTest('created_at', 'asc', false);
+    }
 }