Skip to content

Commit 18ee80a

Browse files
committed
Roles: fixed error upon created_at sorting
Added test to cover core role sorting functionality. For #4350
1 parent 1a56de6 commit 18ee80a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

app/Users/Queries/RolesAllPaginatedAndSorted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function run(int $count, SimpleListOptions $listOptions): LengthAwarePagi
1515
{
1616
$sort = $listOptions->getSort();
1717
if ($sort === 'created_at') {
18-
$sort = 'users.created_at';
18+
$sort = 'roles.created_at';
1919
}
2020

2121
$query = Role::query()->select(['*'])

tests/User/RoleManagementTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,30 @@ public function test_role_permission_removal()
260260

261261
$this->actingAs($viewer)->get($page->getUrl())->assertStatus(404);
262262
}
263+
264+
public function test_index_listing_sorting()
265+
{
266+
$this->asAdmin();
267+
$role = $this->users->createRole();
268+
$role->display_name = 'zz test role';
269+
$role->created_at = now()->addDays(1);
270+
$role->save();
271+
272+
$runTest = function (string $order, string $direction, bool $expectFirstResult) use ($role) {
273+
setting()->putForCurrentUser('roles_sort', $order);
274+
setting()->putForCurrentUser('roles_sort_order', $direction);
275+
$html = $this->withHtml($this->get('/settings/roles'));
276+
$selector = ".item-list-row:first-child a[href$=\"/roles/{$role->id}\"]";
277+
if ($expectFirstResult) {
278+
$html->assertElementExists($selector);
279+
} else {
280+
$html->assertElementNotExists($selector);
281+
}
282+
};
283+
284+
$runTest('name', 'asc', false);
285+
$runTest('name', 'desc', true);
286+
$runTest('created_at', 'desc', true);
287+
$runTest('created_at', 'asc', false);
288+
}
263289
}

0 commit comments

Comments
 (0)