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:
parent
1a56de6cb4
commit
18ee80a743
@ -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(['*'])
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user