1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-11-23 03:12:32 +01:00

Roles: fixed error upon created_at sorting

Added test to cover core role sorting functionality.
For #4350
This commit is contained in:
Dan Brown 2023-07-04 21:52:46 +01:00
parent 1a56de6cb4
commit 18ee80a743
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 27 additions and 1 deletions

View 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(['*'])

View 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);
}
}