diff --git a/config/services.yaml b/config/services.yaml index 0c126bb..a5e2400 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -17,6 +17,7 @@ services: $xmlDump: '@xml_dump.storage' $travelInfoBaseUrl: '%env(APP_TRAVEL_INFO_BASE_URL)%' $logger: '@monolog.logger.core' + $environment: '%kernel.environment%' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/BusProNet/ApiClient.php b/src/BusProNet/ApiClient.php index 0ba3f43..eae914e 100644 --- a/src/BusProNet/ApiClient.php +++ b/src/BusProNet/ApiClient.php @@ -222,6 +222,8 @@ class ApiClient */ public function createBookingInquiry(BookingDto $bookingDto, bool $debug = false): Notification|BookingResponse { + // Forcibly override booking status to generate inquiry payload + $bookingDto->bookingStatus = 'A'; $payload = $this->bookingDataProcessor->createBookingRequestPayload($bookingDto, 'Anfrage'); $data = [ diff --git a/src/Controller/Booking/Create/Step3Controller.php b/src/Controller/Booking/Create/Step3Controller.php index 0dd3a61..8ba2130 100644 --- a/src/Controller/Booking/Create/Step3Controller.php +++ b/src/Controller/Booking/Create/Step3Controller.php @@ -66,8 +66,7 @@ class Step3Controller extends AbstractController if (true === $form->isSubmitted() && true === $form->isValid()) { try { - // Validate booking data with API (inquiry) - $bookingCreateDto->bookingStatus = 'A'; + // Validate booking data with API by submitting an inquiry booking $inquiryResponse = $this->apiClient->createBookingInquiry($bookingCreateDto); if ($inquiryResponse instanceof Notification) { diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 9ebfcbe..713775c 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -26,6 +26,7 @@ class AppExtension extends AbstractExtension return [ new TwigFunction('icon', [AppRuntime::class, 'renderIcon'], ['needs_environment' => true, 'is_safe' => ['html']]), new TwigFunction('is_participant_eligible', [AppRuntime::class, 'isParticipantEligible']), + new TwigFunction('qa_attribute', [AppRuntime::class, 'renderQaAttribute'], ['is_safe' => ['html']]), ]; } } diff --git a/src/Twig/AppRuntime.php b/src/Twig/AppRuntime.php index c98bdab..25d35c0 100644 --- a/src/Twig/AppRuntime.php +++ b/src/Twig/AppRuntime.php @@ -15,6 +15,7 @@ class AppRuntime implements RuntimeExtensionInterface private readonly IntlExtension $intlExtension, private readonly CountryDataProvider $countryDataProvider, private readonly ParticipantEligibilityService $participantEligibilityService, + private readonly string $environment, ) { } @@ -101,4 +102,25 @@ class AppRuntime implements RuntimeExtensionInterface { return $this->participantEligibilityService->isParticipantEligible($bookingDto, $participantIndex); } + + /** + * Renders a QA attribute for testing purposes. + * + * @param string $label The label for the QA attribute + * @param string|null $value The value for the QA attribute + * + * @return string The rendered QA attribute + */ + public function renderQaAttribute(string $label, ?string $value = null): string + { + if ('prod' === $this->environment) { + return ''; + } + + if (null === $value) { + return sprintf(' data-qa-%s', strtolower($label)); + } + + return sprintf(' data-qa-%s="%s"', strtolower($label), $value); + } } diff --git a/templates/booking/create/step_1.html.twig b/templates/booking/create/step_1.html.twig index 2473647..949a7f4 100644 --- a/templates/booking/create/step_1.html.twig +++ b/templates/booking/create/step_1.html.twig @@ -36,7 +36,7 @@ 'attr': { 'hx-post': path('app_booking_create_step_1_refresh'), 'hx-swap': 'none', - 'hx-trigger': 'change' + 'hx-trigger': 'change', } }) }} {% endfor %}