From ec10ca3623ce391597577e9f70d7bc4d6527ad4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 1 Oct 2026 08:43:37 +0200 Subject: [PATCH] feat: offer the accommodation booking PDF download in every status --- .../AccommodationBooking/PdfController.php | 8 ++---- .../accommodation_booking/index.html.twig | 8 ++---- .../accommodation_booking/show.html.twig | 10 +++---- .../PdfControllerTest.php | 28 +++++-------------- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/Controller/Admin/AccommodationBooking/PdfController.php b/src/Controller/Admin/AccommodationBooking/PdfController.php index 0add2e9e..e6157916 100644 --- a/src/Controller/Admin/AccommodationBooking/PdfController.php +++ b/src/Controller/Admin/AccommodationBooking/PdfController.php @@ -21,12 +21,8 @@ class PdfController extends AbstractController #[Route('/admin/accommodation-booking/{id}/pdf', name: 'app_admin_accommodationbooking_pdf')] public function index(AccommodationBooking $booking): Response { - if (false === $booking->isConfirmed()) { - $this->addFlash('warning', 'Ein PDF kann nur für bestätigte Buchungen erstellt werden.'); - - return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]); - } - + // Offered in every status, so the office can check the document before it goes out + // with the confirmation email; it labels itself Angebot or Buchung accordingly. try { return $this->pdfGenerator->createDownloadResponse($booking); } catch (\RuntimeException $e) { diff --git a/templates/admin/accommodation_booking/index.html.twig b/templates/admin/accommodation_booking/index.html.twig index a361b8e4..a1c94660 100644 --- a/templates/admin/accommodation_booking/index.html.twig +++ b/templates/admin/accommodation_booking/index.html.twig @@ -102,11 +102,9 @@ duplizieren - {% if booking.confirmed %} - - PDF herunterladen - - {% endif %} + + PDF herunterladen + {# A record that has been in front of the customer gets discarded, not removed — see DeleteController. #} {% if booking.draft %} diff --git a/templates/admin/accommodation_booking/show.html.twig b/templates/admin/accommodation_booking/show.html.twig index 417a35b6..df4d0b0e 100644 --- a/templates/admin/accommodation_booking/show.html.twig +++ b/templates/admin/accommodation_booking/show.html.twig @@ -313,12 +313,10 @@ hx-swap="beforeend"> duplizieren - {% if booking.confirmed %} - - PDF herunterladen - - {% endif %} + + PDF herunterladen + {% if not booking.confirmed and not booking.discarded %}
diff --git a/tests/Controller/Admin/AccommodationBooking/PdfControllerTest.php b/tests/Controller/Admin/AccommodationBooking/PdfControllerTest.php index 4d5519c0..e32df23d 100644 --- a/tests/Controller/Admin/AccommodationBooking/PdfControllerTest.php +++ b/tests/Controller/Admin/AccommodationBooking/PdfControllerTest.php @@ -18,9 +18,10 @@ use Symfony\Component\HttpFoundation\Response; */ class PdfControllerTest extends TestCase { - public function testAConfirmedBookingIsDownloadedAsPdf(): void + #[DataProvider('statuses')] + public function testABookingInAnyStatusIsDownloadedAsPdf(AccommodationBookingStatus $status): void { - $booking = $this->booking(AccommodationBookingStatus::Confirmed); + $booking = $this->booking($status); $generator = $this->createMock(AccommodationBookingPdfGenerator::class); $generator->expects(self::once()) @@ -33,29 +34,14 @@ class PdfControllerTest extends TestCase self::assertSame(Response::HTTP_OK, $response->getStatusCode()); } - #[DataProvider('nonConfirmedStatuses')] - public function testABookingThatIsNotConfirmedCannotBeDownloaded(AccommodationBookingStatus $status): void - { - $generator = $this->createMock(AccommodationBookingPdfGenerator::class); - $generator->expects(self::never())->method('createDownloadResponse'); - - $controller = new TestablePdfController($generator); - - $response = $controller->index($this->booking($status)); - - self::assertSame(Response::HTTP_FOUND, $response->getStatusCode()); - self::assertSame(['warning'], array_column($controller->flashes, 'type')); - } - /** * @return iterable */ - public static function nonConfirmedStatuses(): iterable + public static function statuses(): iterable { - yield 'draft' => [AccommodationBookingStatus::Draft]; - yield 'open' => [AccommodationBookingStatus::Open]; - yield 'received' => [AccommodationBookingStatus::Received]; - yield 'discarded' => [AccommodationBookingStatus::Discarded]; + foreach (AccommodationBookingStatus::cases() as $status) { + yield $status->name => [$status]; + } } public function testAFailingGeneratorRedirectsWithAFlash(): void