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 $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('erika@example.com') ->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 */ private function houses(Crawler $crawler): array { return $crawler->filter('.timeline-house-label > span:first-child')->each(fn (Crawler $label) => trim($label->text())); } }