fix: show the whole timeline to staff who are also house managers

This commit is contained in:
fromme committed 2026-11-12 11:58:52 +01:00
1 parent 8f4c4d8267
commit 74080b0488
5 files changed
+134 -6

No files matched your search

@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace App\Tests\Controller\Administrative\Assignment;
use App\Entity\Assignment;
use App\Entity\Destination;
use App\Entity\JobProfile;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpFoundation\Response;
/**
* BusPro also lists admins and managers as house managers. Only a house manager without a staff
* role is kept to their own houses; staff see every house, the house filter and the links.
*/
class TimelineControllerTest extends WebTestCase
{
private KernelBrowser $client;
private EntityManagerInterface $entityManager;
protected function setUp(): void
{
$this->client = static::createClient(server: ['HTTPS' => true]);
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->entityManager->createQuery(sprintf('DELETE FROM %s', Assignment::class))->execute();
$this->entityManager->createQuery(sprintf('DELETE FROM %s', Destination::class))->execute();
$this->entityManager->createQuery(sprintf("DELETE FROM %s jobProfile WHERE jobProfile.name = 'Timeline Probe'", JobProfile::class))->execute();
$this->entityManager->createQuery(sprintf('DELETE FROM %s', User::class))->execute();
$jobProfile = (new JobProfile())->setName('Timeline Probe');
$this->entityManager->persist($jobProfile);
foreach ([1 => ['AGR01', 'Rotbach'], 2 => ['DGS01', 'Spinabad']] as $busProId => [$hotelCode, $hotel]) {
$destination = (new Destination())
->setBusProId($busProId)
->setCode($hotelCode)
->setDateFrom(new \DateTimeImmutable('+10 days'))
->setDateTo(new \DateTimeImmutable('+17 days'))
->setProduct('Probe '.$hotel)
->setHotel($hotel)
->setHotelCode($hotelCode)
->setHotelBusProId(1)
->setPickups([])
;
$this->entityManager->persist($destination);
$this->entityManager->persist(
(new Assignment())->setDestination($destination)->setJobProfile($jobProfile)->setAvailableDispositions(1)
);
}
$this->entityManager->flush();
}
public function testStaffWhoAreAlsoHouseManagersSeeEveryHouse(): void
{
$crawler = $this->request(['ROLE_TEAM_ADMIN', 'ROLE_HOUSE_MANAGER']);
$this->assertSame(['Rotbach', 'Spinabad'], $this->houses($crawler));
$this->assertCount(2, $crawler->filter('.timeline-bar a[href*="/administrative/assignment/detail/"]'));
}
public function testAHouseManagerSeesOnlyTheirOwnHousesWithoutLinks(): void
{
$crawler = $this->request(['ROLE_HOUSE_MANAGER']);
$this->assertSame(['Rotbach'], $this->houses($crawler));
$this->assertCount(0, $crawler->filter('.timeline-bar a'));
}
public function testOnlyStaffGetTheHouseFilter(): void
{
$this->request(['ROLE_MANAGER', 'ROLE_HOUSE_MANAGER']);
$this->client->request('GET', '/common/timeline/filter');
$this->assertStringContainsString('Haus/Destination', (string) $this->client->getResponse()->getContent());
$this->request(['ROLE_HOUSE_MANAGER']);
$this->client->request('GET', '/common/timeline/filter');
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
$this->assertStringNotContainsString('Haus/Destination', (string) $this->client->getResponse()->getContent());
}
/**
* @param list<string> $roles
*/
private function request(array $roles): Crawler
{
$this->entityManager->createQuery(sprintf('DELETE FROM %s', User::class))->execute();
$user = (new User())
->setFirstName('Erika')
->setLastName('Muster')
->setEmail('[email protected]')
->setRoles($roles)
->setHotelCodes(['AGR'])
->setBusProAddressId(1)
->setBusProPersonId(1)
;
$this->entityManager->persist($user);
$this->entityManager->flush();
$this->client->loginUser($user);
$crawler = $this->client->request('GET', '/administrative/timeline');
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
return $crawler;
}
/**
* @return list<string>
*/
private function houses(Crawler $crawler): array
{
return $crawler->filter('.timeline-house-label > span:first-child')->each(fn (Crawler $label) => trim($label->text()));
}
}