setIsInquiry(true); $bookingRepository = $this->createMock(AccommodationBookingRepository::class); $bookingRepository->method('findOneBy')->with(['uuid' => $booking->getUuid()])->willReturn($booking); $linkSigner = $this->createMock(AccommodationBookingLinkSigner::class); $linkSigner->method('isValidLinkRequest')->willReturn(true); $breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class); $breakdownCalculator->method('compute')->with($booking)->willReturn(['total' => 1000]); $bookingService = $this->createMock(AccommodationBookingService::class); $bookingService->expects(self::never())->method('acceptBooking'); $twig = $this->createMock(Environment::class); $twig ->expects(self::once()) ->method('render') ->with('groups/booking/offer.html.twig', ['booking' => $booking, 'priceBreakdown' => ['total' => 1000]]) ->willReturn('offer'); $controller = new OfferController($bookingRepository, $linkSigner, $breakdownCalculator, $bookingService, $twig); $response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid())); self::assertSame(Response::HTTP_OK, $response->getStatusCode()); self::assertSame('offer', $response->getContent()); } public function testPostAcceptsInquiryAndRedirectsToSameUrl(): void { $booking = new AccommodationBooking(); $booking->setIsInquiry(true); $bookingRepository = $this->createMock(AccommodationBookingRepository::class); $bookingRepository->method('findOneBy')->willReturn($booking); $linkSigner = $this->createMock(AccommodationBookingLinkSigner::class); $linkSigner->method('isValidLinkRequest')->willReturn(true); $bookingService = $this->createMock(AccommodationBookingService::class); $bookingService->expects(self::once())->method('acceptBooking')->with($booking); $controller = new OfferController( $bookingRepository, $linkSigner, $this->createMock(AccommodationBookingBreakdownCalculator::class), $bookingService, $this->createMock(Environment::class), ); $request = Request::create('/groups/booking/offer/'.$booking->getUuid().'?t=123&_hash=abc', 'POST'); $response = $controller->index($booking->getUuid(), $request); self::assertSame(Response::HTTP_FOUND, $response->getStatusCode()); self::assertSame($request->getUri(), $response->headers->get('Location')); } public function testGetRendersConfirmationWithoutAcceptFormForBooking(): void { $booking = new AccommodationBooking(); $booking->setIsInquiry(false); $bookingRepository = $this->createMock(AccommodationBookingRepository::class); $bookingRepository->method('findOneBy')->willReturn($booking); $linkSigner = $this->createMock(AccommodationBookingLinkSigner::class); $linkSigner->method('isValidLinkRequest')->willReturn(true); $bookingService = $this->createMock(AccommodationBookingService::class); $bookingService->expects(self::never())->method('acceptBooking'); $twig = $this->createMock(Environment::class); $twig->method('render')->with('groups/booking/offer.html.twig', self::anything())->willReturn('confirmed'); $controller = new OfferController( $bookingRepository, $linkSigner, $this->createMock(AccommodationBookingBreakdownCalculator::class), $bookingService, $twig, ); // A POST on an already-accepted booking should not trigger acceptBooking again — falls through to render. $response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid(), 'POST')); self::assertSame(Response::HTTP_OK, $response->getStatusCode()); } public function testInvalidLinkReturnsUnavailableResponse(): void { $booking = new AccommodationBooking(); $bookingRepository = $this->createMock(AccommodationBookingRepository::class); $bookingRepository->method('findOneBy')->willReturn($booking); $linkSigner = $this->createMock(AccommodationBookingLinkSigner::class); $linkSigner->method('isValidLinkRequest')->willReturn(false); $twig = $this->createMock(Environment::class); $twig->method('render')->with('groups/booking/offer_unavailable.html.twig')->willReturn('unavailable'); $controller = new OfferController( $bookingRepository, $linkSigner, $this->createMock(AccommodationBookingBreakdownCalculator::class), $this->createMock(AccommodationBookingService::class), $twig, ); $response = $controller->index($booking->getUuid(), Request::create('/groups/booking/offer/'.$booking->getUuid())); self::assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode()); } public function testUnknownUuidReturnsUnavailableResponse(): void { $bookingRepository = $this->createMock(AccommodationBookingRepository::class); $bookingRepository->method('findOneBy')->willReturn(null); $linkSigner = $this->createMock(AccommodationBookingLinkSigner::class); $linkSigner->expects(self::never())->method('isValidLinkRequest'); $twig = $this->createMock(Environment::class); $twig->method('render')->willReturn('unavailable'); $controller = new OfferController( $bookingRepository, $linkSigner, $this->createMock(AccommodationBookingBreakdownCalculator::class), $this->createMock(AccommodationBookingService::class), $twig, ); $response = $controller->index('unknown-uuid', Request::create('/groups/booking/offer/unknown-uuid')); self::assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode()); } }