feat: admin list filtering and search

This commit is contained in:
Björn Fromme
2026-08-06 10:57:36 +02:00
parent aa8fa5c1b2
commit dd658bf9d6
41 changed files with 1977 additions and 44 deletions
@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);
namespace App\Tests\Form\Admin\Filter;
use App\Entity\User;
use App\Form\Admin\Filter\AccommodationBookingFilterOptionsProvider;
use App\Repository\Groups\AccommodationBookingRepository;
use App\Repository\Groups\AccommodationRepository;
use App\Repository\UserRepository;
use PHPUnit\Framework\TestCase;
class AccommodationBookingFilterOptionsProviderTest extends TestCase
{
public function testSomebodyAssignedWithoutTheRoleStaysFilterable(): void
{
$staff = $this->user(1, '[email protected]');
$formerStaff = $this->user(2, '[email protected]');
$options = $this->provider([$staff], [$formerStaff])->formOptions(true);
self::assertSame(
['[email protected]', '[email protected]'],
array_map(static fn (User $u) => $u->getEmail(), $options['managers']),
'a booking assigned to someone who lost the groups role has to remain findable',
);
}
public function testSomebodyBothAssignedAndOnStaffIsOfferedOnce(): void
{
$manager = $this->user(1, '[email protected]');
$options = $this->provider([$manager], [$manager])->formOptions(true);
self::assertCount(1, $options['managers']);
}
public function testManagersAreSortedByEmail(): void
{
$options = $this->provider(
[$this->user(1, '[email protected]'), $this->user(2, '[email protected]')],
[$this->user(3, '[email protected]')],
)->formOptions(true);
self::assertSame(
['[email protected]', '[email protected]', '[email protected]'],
array_map(static fn (User $u) => $u->getEmail(), $options['managers']),
);
}
public function testStaffWhoCannotSeeOtherBookingsGetNoManagerFilterAtAll(): void
{
$options = $this->provider([$this->user(1, '[email protected]')], [])->formOptions(false);
self::assertFalse($options['can_filter_by_manager']);
self::assertSame([], $options['managers']);
}
public function testTheManagerFilterIsAPermissionNotAConsequenceOfEmptyData(): void
{
// Nobody holds a groups role and nothing is assigned yet — a group admin still gets to
// filter, which is what keeps the "no assignment" triage available on day one.
$options = $this->provider([], [])->formOptions(true);
self::assertTrue($options['can_filter_by_manager']);
self::assertSame([], $options['managers']);
}
/**
* @param User[] $groupsStaff
* @param User[] $assigned
*/
private function provider(array $groupsStaff, array $assigned): AccommodationBookingFilterOptionsProvider
{
$users = $this->createMock(UserRepository::class);
$users->method('findGroupsStaff')->willReturn($groupsStaff);
$bookings = $this->createMock(AccommodationBookingRepository::class);
$bookings->method('findAssignedManagers')->willReturn($assigned);
$accommodations = $this->createMock(AccommodationRepository::class);
$accommodations->method('findBy')->willReturn([]);
return new AccommodationBookingFilterOptionsProvider($users, $bookings, $accommodations);
}
private function user(int $id, string $email): User
{
$user = new User($email);
$idProperty = new \ReflectionProperty(User::class, 'id');
$idProperty->setValue($user, $id);
return $user;
}
}