feat: pre-flight check of agency bookings
addresses #869bqxr4q
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Form\Model\ParticipantDto;
|
|||||||
use App\Form\Model\RoomSelectionDto;
|
use App\Form\Model\RoomSelectionDto;
|
||||||
use App\Service\BookingPriceCalculator;
|
use App\Service\BookingPriceCalculator;
|
||||||
use App\Service\InsuranceManager;
|
use App\Service\InsuranceManager;
|
||||||
|
use function Symfony\Component\String\u;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes booking form data and converts it into BusProNet API payload format.
|
* Processes booking form data and converts it into BusProNet API payload format.
|
||||||
@@ -78,7 +79,7 @@ class BookingDataProcessor
|
|||||||
// Copy address if first participant has no street (indicating empty/incomplete address)
|
// Copy address if first participant has no street (indicating empty/incomplete address)
|
||||||
$isEmpty = null === $participantData->address
|
$isEmpty = null === $participantData->address
|
||||||
|| null === $participantData->address->street
|
|| null === $participantData->address->street
|
||||||
|| '' === trim($participantData->address->street);
|
|| u($participantData->address->street)->trim()->isEmpty();
|
||||||
|
|
||||||
if ($isEmpty) {
|
if ($isEmpty) {
|
||||||
$participantData->address = clone $booking->applicant->address;
|
$participantData->address = clone $booking->applicant->address;
|
||||||
@@ -155,6 +156,9 @@ class BookingDataProcessor
|
|||||||
// Enrich services with data from travel (especially prices)
|
// Enrich services with data from travel (especially prices)
|
||||||
$this->enrichParticipantServicesFromTravel($participantData, $travel);
|
$this->enrichParticipantServicesFromTravel($participantData, $travel);
|
||||||
|
|
||||||
|
// Normalize loaded participant data so the edit flow sees canonical values.
|
||||||
|
$participantData->normalizeLoadedData();
|
||||||
|
|
||||||
$dto->participants[$index] = $participantData;
|
$dto->participants[$index] = $participantData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\BusProNet\Model;
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
use function Symfony\Component\String\u;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a physical address with street, postal code, city, and country information.
|
* Represents a physical address with street, postal code, city, and country information.
|
||||||
@@ -29,6 +30,21 @@ class Address
|
|||||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||||
public ?string $country = null;
|
public ?string $country = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes legacy string data loaded from API/session sources.
|
||||||
|
*
|
||||||
|
* Trims whitespace and converts empty strings to null so load-time audits
|
||||||
|
* and form hydration see canonical values.
|
||||||
|
*/
|
||||||
|
public function normalize(): void
|
||||||
|
{
|
||||||
|
$this->street = $this->normalizeNullableString($this->street);
|
||||||
|
$this->postCode = $this->normalizeNullableString($this->postCode);
|
||||||
|
$this->city = $this->normalizeNullableString($this->city);
|
||||||
|
$this->district = $this->normalizeNullableString($this->district);
|
||||||
|
$this->country = $this->normalizeNullableString($this->country);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the address to API payload format.
|
* Converts the address to API payload format.
|
||||||
*
|
*
|
||||||
@@ -47,4 +63,15 @@ class Address
|
|||||||
'land' => $this->country,
|
'land' => $this->country,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function normalizeNullableString(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trimmed = u($value)->trim()->toString();
|
||||||
|
|
||||||
|
return '' === $trimmed ? null : $trimmed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use App\Service\BookingChangeTracker;
|
|||||||
use App\Service\BookingEditContextFactory;
|
use App\Service\BookingEditContextFactory;
|
||||||
use App\Service\BookingEditDataLoader;
|
use App\Service\BookingEditDataLoader;
|
||||||
use App\Service\BookingEditDraftManager;
|
use App\Service\BookingEditDraftManager;
|
||||||
|
use App\Service\BookingEditPreFlightChecker;
|
||||||
use App\Service\BookingEditSubmitter;
|
use App\Service\BookingEditSubmitter;
|
||||||
use App\Service\BookingSessionManager;
|
use App\Service\BookingSessionManager;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@@ -42,6 +43,7 @@ class IndexController extends AbstractController
|
|||||||
private readonly BookingSessionManager $bookingSessionService,
|
private readonly BookingSessionManager $bookingSessionService,
|
||||||
private readonly BookingChangeTracker $fingerprintService,
|
private readonly BookingChangeTracker $fingerprintService,
|
||||||
private readonly BookingEditContextFactory $editContextFactory,
|
private readonly BookingEditContextFactory $editContextFactory,
|
||||||
|
private readonly BookingEditPreFlightChecker $preFlightChecker,
|
||||||
private readonly BookingEditSubmitter $formSubmitter,
|
private readonly BookingEditSubmitter $formSubmitter,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
@@ -107,8 +109,28 @@ class IndexController extends AbstractController
|
|||||||
$form = $this->createForm(BookingEditType::class, $bookingDto);
|
$form = $this->createForm(BookingEditType::class, $bookingDto);
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
// Pre-flight check is display-only: it helps users find participants that still need work
|
||||||
|
// without turning the overview into a blocking validation state.
|
||||||
|
$missingValueLabelsByParticipantIndex = $this->preFlightChecker
|
||||||
|
->findMissingValueLabelsByParticipantIndex($bookingDto);
|
||||||
|
|
||||||
|
// Keep these states separate:
|
||||||
|
// - $isOverviewSubmitted: the footer form was posted
|
||||||
|
// - $isOverviewFormValid: Symfony accepted the posted data
|
||||||
|
// - $hasBlockingValidationErrors: only non-internal bookings block submission
|
||||||
|
$isOverviewSubmitted = $form->isSubmitted();
|
||||||
|
$isOverviewFormValid = false;
|
||||||
|
|
||||||
|
if (true === $isOverviewSubmitted) {
|
||||||
|
$isOverviewFormValid = $form->isValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasBlockingValidationErrors = true === $isOverviewSubmitted
|
||||||
|
&& false === $isOverviewFormValid
|
||||||
|
&& false === $bookingDto->isInternalAgencyBooking();
|
||||||
|
|
||||||
// Handle form submission (clicking "Buchung aktualisieren")
|
// Handle form submission (clicking "Buchung aktualisieren")
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if (true === $isOverviewSubmitted && (true === $isOverviewFormValid || true === $bookingDto->isInternalAgencyBooking())) {
|
||||||
$submissionResult = $this->formSubmitter->handleSubmission($request, $bookingDto, $bookingId, $user);
|
$submissionResult = $this->formSubmitter->handleSubmission($request, $bookingDto, $bookingId, $user);
|
||||||
$this->applySubmissionResultFlashes($submissionResult);
|
$this->applySubmissionResultFlashes($submissionResult);
|
||||||
|
|
||||||
@@ -119,8 +141,9 @@ class IndexController extends AbstractController
|
|||||||
$bookingDto,
|
$bookingDto,
|
||||||
$bookingData,
|
$bookingData,
|
||||||
$this->fingerprintService->isDirty($bookingDto),
|
$this->fingerprintService->isDirty($bookingDto),
|
||||||
$form->isSubmitted(),
|
$isOverviewSubmitted,
|
||||||
$form->isSubmitted() && false === $form->isValid(),
|
$hasBlockingValidationErrors,
|
||||||
|
$missingValueLabelsByParticipantIndex,
|
||||||
);
|
);
|
||||||
|
|
||||||
$templateData = [
|
$templateData = [
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ use App\Htmx\HxTrait;
|
|||||||
use App\Service\BookingEditContextFactory;
|
use App\Service\BookingEditContextFactory;
|
||||||
use App\Service\BookingEditDataLoader;
|
use App\Service\BookingEditDataLoader;
|
||||||
use App\Service\BookingEditDraftManager;
|
use App\Service\BookingEditDraftManager;
|
||||||
|
use App\Service\ParticipantDataPrefiller;
|
||||||
use App\Service\BookingSessionManager;
|
use App\Service\BookingSessionManager;
|
||||||
use App\Service\ParticipantFormSupport;
|
use App\Service\ParticipantFormSupport;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
@@ -33,6 +35,7 @@ class ParticipantController extends AbstractController
|
|||||||
private readonly BookingEditDraftManager $draftService,
|
private readonly BookingEditDraftManager $draftService,
|
||||||
private readonly BookingEditContextFactory $editContextFactory,
|
private readonly BookingEditContextFactory $editContextFactory,
|
||||||
private readonly BookingSessionManager $bookingSessionService,
|
private readonly BookingSessionManager $bookingSessionService,
|
||||||
|
private readonly ParticipantDataPrefiller $prepopulationService,
|
||||||
private readonly ParticipantFormSupport $participantFormSupportService,
|
private readonly ParticipantFormSupport $participantFormSupportService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
@@ -76,16 +79,26 @@ class ParticipantController extends AbstractController
|
|||||||
|
|
||||||
$this->editContextFactory->prepareBookingDto($bookingDto);
|
$this->editContextFactory->prepareBookingDto($bookingDto);
|
||||||
|
|
||||||
$wrapper = $this->participantFormSupportService->createParticipantEditDto($bookingDto, $index);
|
$form = $this->createParticipantForm($bookingDto, $index);
|
||||||
|
|
||||||
$form = $this->createForm(
|
|
||||||
BookingParticipantType::class,
|
|
||||||
$wrapper,
|
|
||||||
$this->participantFormSupportService->getParticipantFormOptions($bookingDto)
|
|
||||||
);
|
|
||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
$isDummyDataFill = $this->prepopulationService->isDummyDataFillRequested(
|
||||||
|
$bookingDto->participants[$index],
|
||||||
|
$bookingDto->getMode()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (true === $form->isSubmitted() && true === $isDummyDataFill) {
|
||||||
|
$this->prepopulationService->fillDummyParticipant($bookingDto->participants[$index], $index);
|
||||||
|
|
||||||
|
$this->bookingSessionService->saveBookingDto($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||||
|
$this->draftService->saveDraft($user, $bookingId, $bookingDto);
|
||||||
|
|
||||||
|
$form = $this->createParticipantForm($bookingDto, $index);
|
||||||
|
|
||||||
|
return $this->renderParticipantForm($form, $index, $bookingDto, $bookingId, $bookingData);
|
||||||
|
}
|
||||||
|
|
||||||
$notifications = $this->participantFormSupportService->collectAndClearNotifications($bookingDto);
|
$notifications = $this->participantFormSupportService->collectAndClearNotifications($bookingDto);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
@@ -96,20 +109,7 @@ class ParticipantController extends AbstractController
|
|||||||
return $this->redirectToRoute('app_booking_edit', ['bookingId' => $bookingId]);
|
return $this->redirectToRoute('app_booking_edit', ['bookingId' => $bookingId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = $this->editContextFactory->createParticipantContext($bookingDto, $bookingData);
|
return $this->renderParticipantForm($form, $index, $bookingDto, $bookingId, $bookingData);
|
||||||
|
|
||||||
return $this->render('booking/edit/participant.html.twig', [
|
|
||||||
'form' => $form,
|
|
||||||
'participantIndex' => $index,
|
|
||||||
'bookingEditContext' => $context,
|
|
||||||
'bookingDto' => $context->bookingDto,
|
|
||||||
'summaryData' => $context->summaryData,
|
|
||||||
'mutableData' => $context->mutableData,
|
|
||||||
'refreshRouteName' => 'app_booking_edit_participant_refresh',
|
|
||||||
'refreshRouteParams' => ['bookingId' => $bookingId, 'index' => $index],
|
|
||||||
'cancelRouteName' => 'app_booking_edit',
|
|
||||||
'cancelRouteParams' => ['bookingId' => $bookingId],
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -190,6 +190,48 @@ class ParticipantController extends AbstractController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return FormInterface<mixed>
|
||||||
|
*/
|
||||||
|
private function createParticipantForm(BookingDto $bookingDto, int $index): FormInterface
|
||||||
|
{
|
||||||
|
$wrapper = $this->participantFormSupportService->createParticipantEditDto($bookingDto, $index);
|
||||||
|
|
||||||
|
return $this->createForm(
|
||||||
|
BookingParticipantType::class,
|
||||||
|
$wrapper,
|
||||||
|
$this->participantFormSupportService->getParticipantFormOptions($bookingDto)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Booking|null $bookingData
|
||||||
|
* @param FormInterface<mixed> $form
|
||||||
|
*/
|
||||||
|
private function renderParticipantForm(
|
||||||
|
FormInterface $form,
|
||||||
|
int $index,
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $bookingId,
|
||||||
|
?Booking $bookingData,
|
||||||
|
): Response
|
||||||
|
{
|
||||||
|
$context = $this->editContextFactory->createParticipantContext($bookingDto, $bookingData);
|
||||||
|
|
||||||
|
return $this->render('booking/edit/participant.html.twig', [
|
||||||
|
'form' => $form,
|
||||||
|
'participantIndex' => $index,
|
||||||
|
'bookingEditContext' => $context,
|
||||||
|
'bookingDto' => $context->bookingDto,
|
||||||
|
'summaryData' => $context->summaryData,
|
||||||
|
'mutableData' => $context->mutableData,
|
||||||
|
'refreshRouteName' => 'app_booking_edit_participant_refresh',
|
||||||
|
'refreshRouteParams' => ['bookingId' => $bookingId, 'index' => $index],
|
||||||
|
'cancelRouteName' => 'app_booking_edit',
|
||||||
|
'cancelRouteParams' => ['bookingId' => $bookingId],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private function isParticipantCanceled(Booking $bookingData, int $index): bool
|
private function isParticipantCanceled(Booking $bookingData, int $index): bool
|
||||||
{
|
{
|
||||||
return Booking::STATUS_CANCELED === ($bookingData->participantsStatus[$index] ?? null);
|
return Booking::STATUS_CANCELED === ($bookingData->participantsStatus[$index] ?? null);
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||||||
* Form type for edit booking validation.
|
* Form type for edit booking validation.
|
||||||
*
|
*
|
||||||
* This form is used in the card-based UI where participants are edited individually.
|
* This form is used in the card-based UI where participants are edited individually.
|
||||||
* This form validates the complete BookingDto before allowing updates,
|
* It only applies blocking validation for non-internal-agency bookings. Internal-agency
|
||||||
* ensuring all participants have valid and complete data.
|
* bookings rely on the preflight overview warnings and can still be submitted while
|
||||||
|
* participants are incomplete.
|
||||||
*/
|
*/
|
||||||
/** @extends AbstractType<BookingDto> */
|
/** @extends AbstractType<BookingDto> */
|
||||||
class BookingEditType extends AbstractType
|
class BookingEditType extends AbstractType
|
||||||
@@ -34,14 +35,11 @@ class BookingEditType extends AbstractType
|
|||||||
/** @var BookingDto $data */
|
/** @var BookingDto $data */
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
|
||||||
$groups = ['booking_edit'];
|
if ($data->isInternalAgencyBooking()) {
|
||||||
|
return ['booking_edit'];
|
||||||
// Strict validation in edit mode except for internal agency bookings
|
|
||||||
if (false === $data->isInternalAgencyBooking()) {
|
|
||||||
$groups[] = 'strict_required';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $groups;
|
return ['booking_edit', 'strict_required'];
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ class BookingDto
|
|||||||
|
|
||||||
foreach ($this->participants as $participant) {
|
foreach ($this->participants as $participant) {
|
||||||
// Temporary cleanup for older serialized participants restored from session.
|
// Temporary cleanup for older serialized participants restored from session.
|
||||||
$participant->normalizeBodyDimensions();
|
$participant->normalizeLoadedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Old sessions (before c373a989) still carry a full Travel object;
|
// Old sessions (before c373a989) still carry a full Travel object;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class BookingEditContext
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param array<int, ParticipantCardDataDto>|null $cardsData
|
* @param array<int, ParticipantCardDataDto>|null $cardsData
|
||||||
|
* @param array<int, list<string>> $missingValueLabelsByParticipantIndex
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public readonly BookingDto $bookingDto,
|
public readonly BookingDto $bookingDto,
|
||||||
@@ -20,9 +21,10 @@ class BookingEditContext
|
|||||||
public readonly ?BookingMutabilityDto $mutableData,
|
public readonly ?BookingMutabilityDto $mutableData,
|
||||||
public readonly BookingSummaryDto $summaryData,
|
public readonly BookingSummaryDto $summaryData,
|
||||||
public readonly ?array $cardsData = null,
|
public readonly ?array $cardsData = null,
|
||||||
|
public readonly array $missingValueLabelsByParticipantIndex = [],
|
||||||
public readonly bool $isDirty = false,
|
public readonly bool $isDirty = false,
|
||||||
public readonly bool $isSubmitted = false,
|
public readonly bool $isSubmitted = false,
|
||||||
public readonly bool $hasValidationErrors = false,
|
public readonly bool $hasBlockingValidationErrors = false,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use App\BusProNet\Model\Service;
|
|||||||
use App\Validator\Constraints as AppAssert;
|
use App\Validator\Constraints as AppAssert;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
use function Symfony\Component\String\u;
|
||||||
|
|
||||||
#[AppAssert\Participant(groups: ['booking_edit', 'booking_create'])]
|
#[AppAssert\Participant(groups: ['booking_edit', 'booking_create'])]
|
||||||
class ParticipantDto
|
class ParticipantDto
|
||||||
@@ -374,6 +375,37 @@ class ParticipantDto
|
|||||||
$this->shoeSize = $this->normalizeBodyDimensionValue($this->shoeSize);
|
$this->shoeSize = $this->normalizeBodyDimensionValue($this->shoeSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes participant data loaded from API/session sources.
|
||||||
|
*
|
||||||
|
* This is deliberately limited to mechanical cleanup:
|
||||||
|
* - trim whitespace
|
||||||
|
* - convert empty strings to null
|
||||||
|
* - normalize legacy body dimension values
|
||||||
|
*
|
||||||
|
* It does not fill business-required values.
|
||||||
|
*/
|
||||||
|
public function normalizeLoadedData(): void
|
||||||
|
{
|
||||||
|
$this->firstName = $this->normalizeNullableString($this->firstName);
|
||||||
|
$this->lastName = $this->normalizeNullableString($this->lastName);
|
||||||
|
$this->title = $this->normalizeNullableString($this->title);
|
||||||
|
$this->gender = $this->normalizeNullableString($this->gender);
|
||||||
|
$this->nationality = $this->normalizeNullableString($this->nationality);
|
||||||
|
$this->email = $this->normalizeNullableString($this->email);
|
||||||
|
$this->mobile = $this->normalizeNullableString($this->mobile);
|
||||||
|
$this->remarksRoom = $this->normalizeNullableString($this->remarksRoom);
|
||||||
|
$this->licensePlate = $this->normalizeNullableString($this->licensePlate);
|
||||||
|
$this->purchaseVoucherCode = $this->normalizeNullableString($this->purchaseVoucherCode);
|
||||||
|
$this->promoVoucherCode = $this->normalizeNullableString($this->promoVoucherCode);
|
||||||
|
|
||||||
|
if (null !== $this->address) {
|
||||||
|
$this->address->normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->normalizeBodyDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores the DTO from session/serialization data.
|
* Restores the DTO from session/serialization data.
|
||||||
*
|
*
|
||||||
@@ -393,8 +425,7 @@ class ParticipantDto
|
|||||||
$this->address = new Address();
|
$this->address = new Address();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove after all legacy drafts/session snapshots with body-dimension strings have expired.
|
$this->normalizeLoadedData();
|
||||||
$this->normalizeBodyDimensions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function normalizeBodyDimensionValue(mixed $value): ?string
|
private function normalizeBodyDimensionValue(mixed $value): ?string
|
||||||
@@ -407,7 +438,7 @@ class ParticipantDto
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = trim($value);
|
$value = u($value)->trim()->toString();
|
||||||
if ('' === $value || false === ctype_digit($value)) {
|
if ('' === $value || false === ctype_digit($value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -415,22 +446,37 @@ class ParticipantDto
|
|||||||
return (string) (int) $value;
|
return (string) (int) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function normalizeNullableString(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trimmed = u($value)->trim()->toString();
|
||||||
|
|
||||||
|
return '' === $trimmed ? null : $trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates that the applicant (index 0) has a complete address.
|
* Validates that the participant has a complete address when required.
|
||||||
*
|
*
|
||||||
* This callback only applies to the applicant participant. Address validation includes:
|
* In regular create/edit submission flows this only applies to participant 0.
|
||||||
* - Address object must exist
|
* The edit overview preflight checks address fields separately for the applicant only.
|
||||||
* - All required address fields must be filled (street, postCode, city, country)
|
|
||||||
*/
|
*/
|
||||||
#[Assert\Callback(groups: ['strict_required'])]
|
#[Assert\Callback(groups: ['strict_required'])]
|
||||||
public function validateApplicantAddress(ExecutionContextInterface $context): void
|
public function validateApplicantAddress(ExecutionContextInterface $context): void
|
||||||
{
|
{
|
||||||
// Only validate applicant's address
|
// Only validate applicant's address in regular create/edit submission flows.
|
||||||
if (0 !== $this->index) {
|
if (0 !== $this->index) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Address object is required for applicant
|
$this->validateAddressFields($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateAddressFields(ExecutionContextInterface $context): void
|
||||||
|
{
|
||||||
|
// Address object is required for the validated participant
|
||||||
if (null === $this->address) {
|
if (null === $this->address) {
|
||||||
$context->buildViolation('Bitte angeben')
|
$context->buildViolation('Bitte angeben')
|
||||||
->atPath('address')
|
->atPath('address')
|
||||||
@@ -440,25 +486,25 @@ class ParticipantDto
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate address subfields
|
// Validate address subfields
|
||||||
if (null === $this->address->street || '' === trim($this->address->street)) {
|
if (null === $this->address->street || u($this->address->street)->trim()->isEmpty()) {
|
||||||
$context->buildViolation('Bitte angeben')
|
$context->buildViolation('Bitte angeben')
|
||||||
->atPath('address.street')
|
->atPath('address.street')
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $this->address->postCode || '' === trim($this->address->postCode)) {
|
if (null === $this->address->postCode || u($this->address->postCode)->trim()->isEmpty()) {
|
||||||
$context->buildViolation('Bitte angeben')
|
$context->buildViolation('Bitte angeben')
|
||||||
->atPath('address.postCode')
|
->atPath('address.postCode')
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $this->address->city || '' === trim($this->address->city)) {
|
if (null === $this->address->city || u($this->address->city)->trim()->isEmpty()) {
|
||||||
$context->buildViolation('Bitte angeben')
|
$context->buildViolation('Bitte angeben')
|
||||||
->atPath('address.city')
|
->atPath('address.city')
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $this->address->country || '' === trim($this->address->country)) {
|
if (null === $this->address->country || u($this->address->country)->trim()->isEmpty()) {
|
||||||
$context->buildViolation('Bitte angeben')
|
$context->buildViolation('Bitte angeben')
|
||||||
->atPath('address.country')
|
->atPath('address.country')
|
||||||
->addViolation();
|
->addViolation();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\BusProNet\Constants;
|
|||||||
use App\Validator\Constraints as AppAssert;
|
use App\Validator\Constraints as AppAssert;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
use function Symfony\Component\String\u;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper DTO for editing a participant within a booking context.
|
* Wrapper DTO for editing a participant within a booking context.
|
||||||
@@ -36,14 +37,14 @@ class ParticipantEditDto
|
|||||||
* (participants aged 0-2 years at travel date). Babies don't qualify for any
|
* (participants aged 0-2 years at travel date). Babies don't qualify for any
|
||||||
* ski pass and the field is hidden for them.
|
* ski pass and the field is hidden for them.
|
||||||
*
|
*
|
||||||
* In edit mode, this validation is skipped as the ski pass is readonly.
|
* In edit submissions, this validation is skipped as the ski pass is readonly.
|
||||||
*
|
*
|
||||||
* This validation only runs when strict_required group is active.
|
* This validation only runs when strict_required group is active.
|
||||||
*/
|
*/
|
||||||
#[Assert\Callback(groups: ['strict_required'])]
|
#[Assert\Callback(groups: ['strict_required'])]
|
||||||
public function validateSkiPassRequired(ExecutionContextInterface $context): void
|
public function validateSkiPassRequired(ExecutionContextInterface $context): void
|
||||||
{
|
{
|
||||||
// Skip validation in edit mode - ski pass is readonly
|
// Skip validation in edit submissions - ski pass is readonly there.
|
||||||
if (BookingDto::MODE_EDIT === $this->bookingContext->getMode()) {
|
if (BookingDto::MODE_EDIT === $this->bookingContext->getMode()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -70,50 +71,27 @@ class ParticipantEditDto
|
|||||||
* the insurance field is hidden and will be automatically assigned by the bulk
|
* the insurance field is hidden and will be automatically assigned by the bulk
|
||||||
* insurance handler.
|
* insurance handler.
|
||||||
*
|
*
|
||||||
* In edit mode, this validation is skipped entirely because insurance data is
|
* In edit submissions, this validation is skipped entirely because insurance
|
||||||
* readonly and preserved as-is from the BPN API (the insurance field handler
|
* data is readonly and preserved as-is from the BPN API.
|
||||||
* does not process insurance in edit mode).
|
|
||||||
*
|
*
|
||||||
* This validation only runs when strict_required group is active.
|
* This validation only runs when strict_required group is active.
|
||||||
*/
|
*/
|
||||||
#[Assert\Callback(groups: ['strict_required'])]
|
#[Assert\Callback(groups: ['strict_required'])]
|
||||||
public function validateInsuranceRequired(ExecutionContextInterface $context): void
|
public function validateInsuranceRequired(ExecutionContextInterface $context): void
|
||||||
{
|
{
|
||||||
// Skip validation in edit mode - insurance is readonly and preserved as-is
|
// Skip validation in edit submissions - insurance is readonly and preserved as-is.
|
||||||
if (BookingDto::MODE_EDIT === $this->bookingContext->getMode()) {
|
if (BookingDto::MODE_EDIT === $this->bookingContext->getMode()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insurance is always required for applicant in create mode
|
if (false === $this->participant->isApplicant()) {
|
||||||
if (true === $this->participant->isApplicant()) {
|
$applicant = $this->bookingContext->getParticipant(0);
|
||||||
if (null === $this->participant->insurance) {
|
|
||||||
$context->buildViolation('Bitte auswählen')
|
if (true === $applicant?->bulkInsuranceBooking) {
|
||||||
->atPath('participant.insurance')
|
return;
|
||||||
->addViolation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For dependent participants, check if bulk insurance is active
|
|
||||||
$applicant = $this->bookingContext->getParticipant(0);
|
|
||||||
if (null === $applicant) {
|
|
||||||
// Applicant not found - shouldn't happen, but validate insurance to be safe
|
|
||||||
if (null === $this->participant->insurance) {
|
|
||||||
$context->buildViolation('Bitte auswählen')
|
|
||||||
->atPath('participant.insurance')
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If bulk insurance booking is active, skip validation (field is hidden, will be auto-assigned)
|
|
||||||
if (true === $applicant->bulkInsuranceBooking) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bulk insurance not active - insurance is required
|
|
||||||
if (null === $this->participant->insurance) {
|
if (null === $this->participant->insurance) {
|
||||||
$context->buildViolation('Bitte auswählen')
|
$context->buildViolation('Bitte auswählen')
|
||||||
->atPath('participant.insurance')
|
->atPath('participant.insurance')
|
||||||
@@ -138,7 +116,7 @@ class ParticipantEditDto
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip validation for applicant (index 0) - applicant's email can be shared with dependents
|
// In regular create/edit submission flows, the applicant can share an email with dependents.
|
||||||
if (true === $this->participant->isApplicant()) {
|
if (true === $this->participant->isApplicant()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -149,12 +127,12 @@ class ParticipantEditDto
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip if email is null or empty (handled by @Email and @NotBlank constraints)
|
// Skip if email is null or empty (handled by @Email and @NotBlank constraints)
|
||||||
if (null === $this->participant->email || '' === trim($this->participant->email)) {
|
if (null === $this->participant->email || u($this->participant->email)->trim()->isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize current participant's email for comparison
|
// Normalize current participant's email for comparison
|
||||||
$normalizedEmail = strtolower(trim($this->participant->email));
|
$normalizedEmail = u($this->participant->email)->trim()->lower()->toString();
|
||||||
|
|
||||||
// Check against all adult participants in booking context
|
// Check against all adult participants in booking context
|
||||||
foreach ($this->bookingContext->participants as $index => $otherParticipant) {
|
foreach ($this->bookingContext->participants as $index => $otherParticipant) {
|
||||||
@@ -169,12 +147,12 @@ class ParticipantEditDto
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip null or empty emails
|
// Skip null or empty emails
|
||||||
if (null === $otherParticipant->email || '' === trim($otherParticipant->email)) {
|
if (null === $otherParticipant->email || u($otherParticipant->email)->trim()->isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare normalized emails
|
// Compare normalized emails
|
||||||
$otherNormalizedEmail = strtolower(trim($otherParticipant->email));
|
$otherNormalizedEmail = u($otherParticipant->email)->trim()->lower()->toString();
|
||||||
|
|
||||||
if ($normalizedEmail === $otherNormalizedEmail) {
|
if ($normalizedEmail === $otherNormalizedEmail) {
|
||||||
// Add violation to participant.email path
|
// Add violation to participant.email path
|
||||||
|
|||||||
@@ -45,22 +45,29 @@ class BookingEditContextFactory
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, list<string>> $missingValueLabelsByParticipantIndex
|
||||||
|
*/
|
||||||
public function createOverviewContext(
|
public function createOverviewContext(
|
||||||
BookingDto $bookingDto,
|
BookingDto $bookingDto,
|
||||||
Booking $bookingData,
|
Booking $bookingData,
|
||||||
bool $isDirty,
|
bool $isDirty,
|
||||||
bool $isSubmitted,
|
bool $isSubmitted,
|
||||||
bool $hasValidationErrors,
|
bool $hasBlockingValidationErrors,
|
||||||
|
array $missingValueLabelsByParticipantIndex = [],
|
||||||
): BookingEditContext {
|
): BookingEditContext {
|
||||||
|
$cardsData = $this->participantCardDataService->getAllCardsDataWithValidation($bookingDto);
|
||||||
|
|
||||||
return new BookingEditContext(
|
return new BookingEditContext(
|
||||||
bookingDto: $bookingDto,
|
bookingDto: $bookingDto,
|
||||||
bookingData: $bookingData,
|
bookingData: $bookingData,
|
||||||
mutableData: BookingMutabilityDto::fromBaseData($this->travelDataService->getMutabilityData($bookingData->dateId)),
|
mutableData: BookingMutabilityDto::fromBaseData($this->travelDataService->getMutabilityData($bookingData->dateId)),
|
||||||
summaryData: $this->createSummaryData($bookingDto),
|
summaryData: $this->createSummaryData($bookingDto),
|
||||||
cardsData: $this->participantCardDataService->getAllCardsDataWithValidation($bookingDto),
|
cardsData: $cardsData,
|
||||||
|
missingValueLabelsByParticipantIndex: $missingValueLabelsByParticipantIndex,
|
||||||
isDirty: $isDirty,
|
isDirty: $isDirty,
|
||||||
isSubmitted: $isSubmitted,
|
isSubmitted: $isSubmitted,
|
||||||
hasValidationErrors: $hasValidationErrors,
|
hasBlockingValidationErrors: $hasBlockingValidationErrors,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ class BookingEditDraftMerger
|
|||||||
if (isset($data['services']) && true === is_array($data['services'])) {
|
if (isset($data['services']) && true === is_array($data['services'])) {
|
||||||
$this->applyServiceSelections($participant, $data['services'], $travel);
|
$this->applyServiceSelections($participant, $data['services'], $travel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$participant->normalizeLoadedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function canApplyPersonalDataDraft(BookingDto $bookingDto, int $participantIndex, ParticipantDto $participant): bool
|
private function canApplyPersonalDataDraft(BookingDto $bookingDto, int $participantIndex, ParticipantDto $participant): bool
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Model\ParticipantEditDto;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects edit-overview participants that still need user attention.
|
||||||
|
*
|
||||||
|
* This is display-only: it highlights participants that still need work
|
||||||
|
* without affecting whether the edit submit is allowed.
|
||||||
|
*
|
||||||
|
* The scan uses the participant edit wrapper so participant-scoped validation
|
||||||
|
* follows the same booking-context rules as the participant form. Body
|
||||||
|
* dimensions are optional; only provided values are checked against the range
|
||||||
|
* validator unless a selection-based exemption applies.
|
||||||
|
*/
|
||||||
|
class BookingEditPreFlightChecker
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly ValidatorInterface $validator,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the display-only attention scan for the edit overview.
|
||||||
|
*
|
||||||
|
* Canceled participants are ignored because they are not actionable.
|
||||||
|
*
|
||||||
|
* @return array<int, list<string>>
|
||||||
|
*/
|
||||||
|
public function findMissingValueLabelsByParticipantIndex(BookingDto $bookingDto): array
|
||||||
|
{
|
||||||
|
if (BookingDto::MODE_EDIT !== $bookingDto->getMode()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$missingValueLabelsByParticipantIndex = [];
|
||||||
|
|
||||||
|
foreach ($bookingDto->participants as $index => $participant) {
|
||||||
|
if (true === $participant->isCanceled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$missingValueLabels = $this->getMissingValueLabelsForParticipant($bookingDto, $participant);
|
||||||
|
|
||||||
|
if ([] !== $missingValueLabels) {
|
||||||
|
$missingValueLabelsByParticipantIndex[$index] = $missingValueLabels;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $missingValueLabelsByParticipantIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function getMissingValueLabelsForParticipant(BookingDto $bookingDto, ParticipantDto $participant): array
|
||||||
|
{
|
||||||
|
$participantForAudit = new ParticipantEditDto(
|
||||||
|
participant: $participant,
|
||||||
|
bookingContext: $bookingDto,
|
||||||
|
);
|
||||||
|
|
||||||
|
$violations = $this->validator->validate(
|
||||||
|
$participantForAudit,
|
||||||
|
null,
|
||||||
|
['booking_edit', 'strict_required']
|
||||||
|
);
|
||||||
|
|
||||||
|
$valueLabels = [];
|
||||||
|
|
||||||
|
foreach ($violations as $violation) {
|
||||||
|
$valueLabel = $this->mapViolationToValueLabel($violation);
|
||||||
|
if (null !== $valueLabel) {
|
||||||
|
$valueLabels[] = $valueLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $bookingDto->isInternalAgencyBooking() && true === $participant->isApplicant()) {
|
||||||
|
foreach ($this->getMissingValueAddressLabels($participant) as $valueLabel) {
|
||||||
|
$valueLabels[] = $valueLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_unique($valueLabels));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function mapViolationToValueLabel(ConstraintViolationInterface $violation): ?string
|
||||||
|
{
|
||||||
|
$propertyPath = $violation->getPropertyPath();
|
||||||
|
|
||||||
|
if (str_starts_with($propertyPath, 'participant.')) {
|
||||||
|
$propertyPath = substr($propertyPath, strlen('participant.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return match ($propertyPath) {
|
||||||
|
'firstName' => 'Vorname',
|
||||||
|
'lastName' => 'Nachname',
|
||||||
|
'gender' => 'Anrede',
|
||||||
|
'nationality' => 'Nationalität',
|
||||||
|
'dateOfBirth' => 'Geburtsdatum',
|
||||||
|
'email' => 'E-Mail',
|
||||||
|
'height' => 'Körpergröße',
|
||||||
|
'weight' => 'Gewicht',
|
||||||
|
'shoeSize' => 'Schuhgröße',
|
||||||
|
'assignedRoomId' => 'Zimmer',
|
||||||
|
'transportationOutbound' => 'Anreise',
|
||||||
|
'pickup' => 'Zustieg',
|
||||||
|
'transportationInbound' => 'Abreise',
|
||||||
|
'dropOff' => 'Ausstieg',
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
private function getMissingValueAddressLabels(ParticipantDto $participant): array
|
||||||
|
{
|
||||||
|
if (null === $participant->address) {
|
||||||
|
return ['Adresse'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$valueLabels = [];
|
||||||
|
$violations = $this->validator->validate($participant->address, null, ['personal_data']);
|
||||||
|
|
||||||
|
foreach ($violations as $violation) {
|
||||||
|
$valueLabel = match ($violation->getPropertyPath()) {
|
||||||
|
'street' => 'Straße',
|
||||||
|
'postCode' => 'PLZ',
|
||||||
|
'city' => 'Ort',
|
||||||
|
'country' => 'Land',
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (null !== $valueLabel) {
|
||||||
|
$valueLabels[] = $valueLabel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_unique($valueLabels));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,18 @@ class ParticipantCardAssembler
|
|||||||
* Get card data for a single participant.
|
* Get card data for a single participant.
|
||||||
*/
|
*/
|
||||||
public function getCardData(BookingDto $bookingDto, int $index): ParticipantCardDataDto
|
public function getCardData(BookingDto $bookingDto, int $index): ParticipantCardDataDto
|
||||||
|
{
|
||||||
|
return $this->buildCardData($bookingDto, $index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, float>|null $precomputedPrices
|
||||||
|
*/
|
||||||
|
private function buildCardData(
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $index,
|
||||||
|
?array $precomputedPrices = null,
|
||||||
|
): ParticipantCardDataDto
|
||||||
{
|
{
|
||||||
$participant = $bookingDto->participants[$index] ?? null;
|
$participant = $bookingDto->participants[$index] ?? null;
|
||||||
|
|
||||||
@@ -45,7 +57,7 @@ class ParticipantCardAssembler
|
|||||||
$roomName = $this->getRoomName($bookingDto, $participant);
|
$roomName = $this->getRoomName($bookingDto, $participant);
|
||||||
|
|
||||||
// Calculate pricing state for display
|
// Calculate pricing state for display
|
||||||
$priceData = $this->getPriceData($bookingDto, $index);
|
$priceData = $this->getPriceData($bookingDto, $index, $precomputedPrices);
|
||||||
|
|
||||||
// Check if participant is canceled
|
// Check if participant is canceled
|
||||||
$isCanceled = $participant->isCanceled();
|
$isCanceled = $participant->isCanceled();
|
||||||
@@ -67,9 +79,10 @@ class ParticipantCardAssembler
|
|||||||
public function getAllCardsData(BookingDto $bookingDto): array
|
public function getAllCardsData(BookingDto $bookingDto): array
|
||||||
{
|
{
|
||||||
$cardsData = [];
|
$cardsData = [];
|
||||||
|
$prices = $this->calculateBulkParticipantPrices($bookingDto);
|
||||||
|
|
||||||
foreach ($bookingDto->participants as $index => $_participant) {
|
foreach ($bookingDto->participants as $index => $_participant) {
|
||||||
$cardsData[$index] = $this->getCardData($bookingDto, $index);
|
$cardsData[$index] = $this->buildCardData($bookingDto, $index, $prices);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cardsData;
|
return $cardsData;
|
||||||
@@ -122,8 +135,14 @@ class ParticipantCardAssembler
|
|||||||
*
|
*
|
||||||
* Returns a dash marker when the price is zero and no room is assigned,
|
* Returns a dash marker when the price is zero and no room is assigned,
|
||||||
* indicating incomplete configuration rather than a zero-cost booking.
|
* indicating incomplete configuration rather than a zero-cost booking.
|
||||||
|
*
|
||||||
|
* @param array<int, float>|null $precomputedPrices
|
||||||
*/
|
*/
|
||||||
private function getPriceData(BookingDto $bookingDto, int $index): ParticipantCardPriceDto
|
private function getPriceData(
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $index,
|
||||||
|
?array $precomputedPrices = null,
|
||||||
|
): ParticipantCardPriceDto
|
||||||
{
|
{
|
||||||
// Check if canceled (only possible in edit mode when booking property is set)
|
// Check if canceled (only possible in edit mode when booking property is set)
|
||||||
$isCanceled = ($bookingDto->booking?->participantsStatus[$index] ?? null) === 'S';
|
$isCanceled = ($bookingDto->booking?->participantsStatus[$index] ?? null) === 'S';
|
||||||
@@ -150,7 +169,7 @@ class ParticipantCardAssembler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For active participants: existing price calculation logic
|
// For active participants: existing price calculation logic
|
||||||
$prices = $this->priceCalculator->calculateAllParticipantIndividualPrices($bookingDto);
|
$prices = $precomputedPrices ?? $this->priceCalculator->calculateAllParticipantIndividualPrices($bookingDto);
|
||||||
|
|
||||||
$price = $prices[$index] ?? 0.0;
|
$price = $prices[$index] ?? 0.0;
|
||||||
|
|
||||||
@@ -166,8 +185,92 @@ class ParticipantCardAssembler
|
|||||||
/**
|
/**
|
||||||
* Get card data for a single participant with validation state.
|
* Get card data for a single participant with validation state.
|
||||||
*/
|
*/
|
||||||
public function getCardDataWithValidation(BookingDto $bookingDto, int $index): ParticipantCardDataDto
|
public function getCardDataWithValidation(
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $index,
|
||||||
|
bool $forceStrictRequired = false,
|
||||||
|
): ParticipantCardDataDto
|
||||||
{
|
{
|
||||||
|
return $this->getCardDataWithValidationInternal(
|
||||||
|
$bookingDto,
|
||||||
|
$index,
|
||||||
|
$this->determineValidationGroups($bookingDto, $forceStrictRequired)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get card data for all participants with validation state.
|
||||||
|
*
|
||||||
|
* @return array<int, ParticipantCardDataDto>
|
||||||
|
*/
|
||||||
|
public function getAllCardsDataWithValidation(BookingDto $bookingDto, bool $forceStrictRequired = false): array
|
||||||
|
{
|
||||||
|
$cardsData = [];
|
||||||
|
$prices = $this->calculateBulkParticipantPrices($bookingDto);
|
||||||
|
$validationGroups = $this->determineValidationGroups($bookingDto, $forceStrictRequired);
|
||||||
|
|
||||||
|
foreach ($bookingDto->participants as $index => $_participant) {
|
||||||
|
$cardsData[$index] = $this->getCardDataWithValidationInternal(
|
||||||
|
$bookingDto,
|
||||||
|
$index,
|
||||||
|
$validationGroups,
|
||||||
|
$prices
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cardsData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, float>
|
||||||
|
*/
|
||||||
|
private function calculateBulkParticipantPrices(BookingDto $bookingDto): array
|
||||||
|
{
|
||||||
|
foreach ($bookingDto->participants as $index => $_participant) {
|
||||||
|
if (($bookingDto->booking?->participantsStatus[$index] ?? null) !== 'S') {
|
||||||
|
return $this->priceCalculator->calculateAllParticipantIndividualPrices($bookingDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines validation groups based on booking mode and applicant mutability.
|
||||||
|
*
|
||||||
|
* @return array<string> Validation groups to apply
|
||||||
|
*/
|
||||||
|
private function determineValidationGroups(BookingDto $bookingDto, bool $forceStrictRequired = false): array
|
||||||
|
{
|
||||||
|
$groups = [];
|
||||||
|
|
||||||
|
// Add mode-specific group
|
||||||
|
if (BookingDto::MODE_CREATE === $bookingDto->getMode()) {
|
||||||
|
$groups[] = 'booking_create';
|
||||||
|
$groups[] = 'strict_required';
|
||||||
|
} else {
|
||||||
|
$groups[] = 'booking_edit';
|
||||||
|
|
||||||
|
// Strict validation in edit mode except for internal agency bookings,
|
||||||
|
// unless the caller explicitly asks for the full validation set.
|
||||||
|
if (true === $forceStrictRequired || false === $bookingDto->isInternalAgencyBooking()) {
|
||||||
|
$groups[] = 'strict_required';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string> $validationGroups
|
||||||
|
* @param array<int, float>|null $precomputedPrices
|
||||||
|
*/
|
||||||
|
private function getCardDataWithValidationInternal(
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
int $index,
|
||||||
|
array $validationGroups,
|
||||||
|
?array $precomputedPrices = null,
|
||||||
|
): ParticipantCardDataDto {
|
||||||
$participant = $bookingDto->participants[$index] ?? null;
|
$participant = $bookingDto->participants[$index] ?? null;
|
||||||
|
|
||||||
if (null === $participant) {
|
if (null === $participant) {
|
||||||
@@ -175,17 +278,13 @@ class ParticipantCardAssembler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get basic card data
|
// Get basic card data
|
||||||
$cardData = $this->getCardData($bookingDto, $index);
|
$cardData = $this->buildCardData($bookingDto, $index, $precomputedPrices);
|
||||||
|
|
||||||
// Wrap participant for validation
|
|
||||||
$wrapper = new ParticipantEditDto(
|
$wrapper = new ParticipantEditDto(
|
||||||
participant: $participant,
|
participant: $participant,
|
||||||
bookingContext: $bookingDto,
|
bookingContext: $bookingDto,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Determine validation groups based on mode and mutability
|
|
||||||
$validationGroups = $this->determineValidationGroups($bookingDto);
|
|
||||||
|
|
||||||
// Validate the wrapper DTO
|
// Validate the wrapper DTO
|
||||||
$violations = $this->validator->validate($wrapper, null, $validationGroups);
|
$violations = $this->validator->validate($wrapper, null, $validationGroups);
|
||||||
|
|
||||||
@@ -199,45 +298,4 @@ class ParticipantCardAssembler
|
|||||||
|
|
||||||
return $cardData->withValidation($isValid, $errorMessages);
|
return $cardData->withValidation($isValid, $errorMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get card data for all participants with validation state.
|
|
||||||
*
|
|
||||||
* @return array<int, ParticipantCardDataDto>
|
|
||||||
*/
|
|
||||||
public function getAllCardsDataWithValidation(BookingDto $bookingDto): array
|
|
||||||
{
|
|
||||||
$cardsData = [];
|
|
||||||
|
|
||||||
foreach ($bookingDto->participants as $index => $_participant) {
|
|
||||||
$cardsData[$index] = $this->getCardDataWithValidation($bookingDto, $index);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cardsData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines validation groups based on booking mode and applicant mutability.
|
|
||||||
*
|
|
||||||
* @return array<string> Validation groups to apply
|
|
||||||
*/
|
|
||||||
private function determineValidationGroups(BookingDto $bookingDto): array
|
|
||||||
{
|
|
||||||
$groups = [];
|
|
||||||
|
|
||||||
// Add mode-specific group
|
|
||||||
if (BookingDto::MODE_CREATE === $bookingDto->getMode()) {
|
|
||||||
$groups[] = 'booking_create';
|
|
||||||
$groups[] = 'strict_required';
|
|
||||||
} else {
|
|
||||||
$groups[] = 'booking_edit';
|
|
||||||
|
|
||||||
// Strict validation in edit mode except for internal agency bookings
|
|
||||||
if (false === $bookingDto->isInternalAgencyBooking()) {
|
|
||||||
$groups[] = 'strict_required';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $groups;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,15 +112,9 @@ class ParticipantDataPrefiller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the participant's last name triggers dummy data fill.
|
* Checks if the participant's last name triggers dummy data fill.
|
||||||
*
|
|
||||||
* Only matches in create mode to avoid accidental triggering during edits.
|
|
||||||
*/
|
*/
|
||||||
public function isDummyDataFillRequested(ParticipantDto $participant, string $mode): bool
|
public function isDummyDataFillRequested(ParticipantDto $participant, string $mode): bool
|
||||||
{
|
{
|
||||||
if (BookingDto::MODE_CREATE !== $mode) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::TOKEN === $participant->lastName;
|
return self::TOKEN === $participant->lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="{{ html_classes('rounded-md mb-4', { 'p-4': modal == false, 'bg-red-500': level == 'error', 'bg-green-500': level == 'success', 'bg-yellow-500': level == 'warning', 'bg-primary-light': level == 'info' }) }}">
|
<div class="{{ html_classes('rounded-md mb-4', { 'p-4': modal == false, 'bg-red-500': level == 'error', 'bg-green-500': level == 'success', 'bg-yellow-500': level == 'warning', 'bg-primary-light': level == 'info' }) }}">
|
||||||
<div class="flex items-start">
|
<div class="flex items-start">
|
||||||
<div class="shrink-0 text-white mt-1">
|
<div class="{{ html_classes('shrink-0 mt-1', { 'text-gray-800': level == 'warning', 'text-white': level != 'warning' }) }}">
|
||||||
{% if level == 'error' or level == 'warning' %}
|
{% if level == 'error' or level == 'warning' %}
|
||||||
<svg class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
<svg class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||||
<path fill-rule="evenodd" d="M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM8.28 7.22a.75.75 0 0 0-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 1 0 1.06 1.06L10 11.06l1.72 1.72a.75.75 0 1 0 1.06-1.06L11.06 10l1.72-1.72a.75.75 0 0 0-1.06-1.06L10 8.94 8.28 7.22Z" clip-rule="evenodd" />
|
<path fill-rule="evenodd" d="M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM8.28 7.22a.75.75 0 0 0-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 1 0 1.06 1.06L10 11.06l1.72 1.72a.75.75 0 1 0 1.06-1.06L11.06 10l1.72-1.72a.75.75 0 0 0-1.06-1.06L10 8.94 8.28 7.22Z" clip-rule="evenodd" />
|
||||||
@@ -20,12 +20,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="ml-3">
|
<div class="ml-3">
|
||||||
{% if title is defined %}
|
{% if title is defined %}
|
||||||
<div class="text-white text-lg font-semibold uppercase">
|
<div class="{{ html_classes('text-lg font-semibold uppercase', { 'text-gray-800': level == 'warning', 'text-white': level != 'warning' }) }}">
|
||||||
{{ title }}
|
{{ title }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if messages is defined %}
|
{% if messages is defined %}
|
||||||
<div class="text-white">
|
<div class="{{ html_classes({ 'text-gray-800': level == 'warning', 'text-white': level != 'warning' }) }}">
|
||||||
<ul role="list" class="space-y-1">
|
<ul role="list" class="space-y-1">
|
||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@@ -2,10 +2,13 @@
|
|||||||
{% set isCanceled = cardData.isCanceled is defined ? cardData.isCanceled : false %}
|
{% set isCanceled = cardData.isCanceled is defined ? cardData.isCanceled : false %}
|
||||||
{% set isValid = cardData.isValid is defined ? cardData.isValid : true %}
|
{% set isValid = cardData.isValid is defined ? cardData.isValid : true %}
|
||||||
{% set isSubmitted = isSubmitted|default(false) %}
|
{% set isSubmitted = isSubmitted|default(false) %}
|
||||||
|
{% set needsAttention = needsAttention|default(false) %}
|
||||||
|
{% set attentionLabels = attentionLabels|default([]) %}
|
||||||
{% set mode = mode|default('create') %}
|
{% set mode = mode|default('create') %}
|
||||||
|
|
||||||
{# Determine display states #}
|
{# Determine display states #}
|
||||||
{% set showAsError = not isValid and isSubmitted %}
|
{% set showAsError = not isValid and isSubmitted %}
|
||||||
|
{% set showAsAttention = needsAttention and not showAsError %}
|
||||||
{% set showAsIncomplete = not isValid and not isSubmitted %}
|
{% set showAsIncomplete = not isValid and not isSubmitted %}
|
||||||
|
|
||||||
{# Build edit URL for linking #}
|
{# Build edit URL for linking #}
|
||||||
@@ -17,11 +20,13 @@
|
|||||||
|
|
||||||
<div class="py-4" id="participant-card-{{ index }}">
|
<div class="py-4" id="participant-card-{{ index }}">
|
||||||
<div class="flex items-start space-x-4">
|
<div class="flex items-start space-x-4">
|
||||||
<div class="{{ html_classes('w-12 h-12 inline-flex flex-shrink-0 items-center justify-center rounded-full text-white font-bold', {
|
<div class="{{ html_classes('w-12 h-12 inline-flex flex-shrink-0 items-center justify-center rounded-full font-bold', {
|
||||||
'bg-primary-dark': not showAsError and booking_theme() == 'base',
|
'text-white': not showAsAttention,
|
||||||
'bg-sbw-primary': not showAsError and booking_theme() == 'sbw',
|
'bg-yellow-500': showAsAttention,
|
||||||
'bg-snz-primary-dark': not showAsError and booking_theme() == 'snz',
|
'bg-primary-dark': not showAsError and not showAsAttention and booking_theme() == 'base',
|
||||||
'bg-ser-primary': not showAsError and booking_theme() == 'ser',
|
'bg-sbw-primary': not showAsError and not showAsAttention and booking_theme() == 'sbw',
|
||||||
|
'bg-snz-primary-dark': not showAsError and not showAsAttention and booking_theme() == 'snz',
|
||||||
|
'bg-ser-primary': not showAsError and not showAsAttention and booking_theme() == 'ser',
|
||||||
'bg-red-500': showAsError,
|
'bg-red-500': showAsError,
|
||||||
'text-2xl': participantNumber < 100,
|
'text-2xl': participantNumber < 100,
|
||||||
'text-xl': participantNumber >= 100,
|
'text-xl': participantNumber >= 100,
|
||||||
@@ -37,13 +42,26 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if isCanceled %}
|
{% if isCanceled %}
|
||||||
<div class="text-xs font-medium text-gray-700" {{ qa_attribute('participant-canceled', index) }}>
|
<div class="text-sm font-medium text-gray-700" {{ qa_attribute('participant-canceled', index) }}>
|
||||||
storniert
|
storniert
|
||||||
</div>
|
</div>
|
||||||
{% elseif showAsError %}
|
{% elseif showAsError %}
|
||||||
<div class="text-xs font-medium text-red-500" {{ qa_attribute('participant-invalid', index) }}>
|
<div class="text-sm font-medium text-red-500" {{ qa_attribute('participant-invalid', index) }}>
|
||||||
unvollständige/fehlerhafte Daten
|
unvollständige/fehlerhafte Daten
|
||||||
</div>
|
</div>
|
||||||
|
{% elseif showAsAttention %}
|
||||||
|
<div class="text-sm font-medium text-red-500" {{ qa_attribute('participant-attention', index) }}>
|
||||||
|
bitte prüfen/ergänzen:
|
||||||
|
</div>
|
||||||
|
{% if attentionLabels|length > 0 %}
|
||||||
|
<div class="mt-2 flex flex-wrap gap-1" {{ qa_attribute('participant-attention-labels', index) }}>
|
||||||
|
{% for label in attentionLabels %}
|
||||||
|
<span class="inline-flex items-center rounded-full bg-yellow-500 px-2 py-0.5 text-xs font-semibold">
|
||||||
|
{{ label }}
|
||||||
|
</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="text-gray-600" {{ qa_attribute('participant-room-name', index) }}>
|
<div class="text-gray-600" {{ qa_attribute('participant-room-name', index) }}>
|
||||||
{{ cardData.roomName }}
|
{{ cardData.roomName }}
|
||||||
|
|||||||
@@ -62,18 +62,25 @@
|
|||||||
} %}
|
} %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# Display validation errors #}
|
{# Display blocking issues first; otherwise show the attention scan as a calm warning #}
|
||||||
{% if bookingEditContext.hasValidationErrors %}
|
{% if bookingEditContext.hasBlockingValidationErrors %}
|
||||||
{% include '_partials/_alert.html.twig' with {
|
{% include '_partials/_alert.html.twig' with {
|
||||||
level: 'error',
|
level: 'error',
|
||||||
title: 'Bitte überprüfe die Teilnehmerdaten',
|
title: 'Teilnehmerdaten prüfen',
|
||||||
messages: ['Einige Teilnehmer haben noch unvollständige oder fehlerhafte Angaben. Bitte bearbeite die markierten Teilnehmer.']
|
messages: ['Die Daten einiger Teilnehmer:innen sind noch unvollständig oder fehlerhaft. Bitte bearbeite die markierten Teilnehmer.']
|
||||||
|
} %}
|
||||||
|
{% elseif bookingEditContext.missingValueLabelsByParticipantIndex|length > 0 %}
|
||||||
|
{% include '_partials/_alert.html.twig' with {
|
||||||
|
level: 'warning',
|
||||||
|
title: 'Teilnehmerdaten prüfen',
|
||||||
|
messages: ['Die Daten von ' ~ (bookingEditContext.missingValueLabelsByParticipantIndex|length) ~ ' Teilnehmer:innen sind noch unvollständig oder fehlerhaft. Bitte bearbeite die markierten Teilnehmer.']
|
||||||
} %}
|
} %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div id="participant-cards-grid" class="space-y-4">
|
<div id="participant-cards-grid" class="divide-y divide-gray-200">
|
||||||
{% for participant in bookingEditContext.bookingDto.participants %}
|
{% for participant in bookingEditContext.bookingDto.participants %}
|
||||||
{% set isCanceled = (bookingEditContext.bookingData.participantsStatus[loop.index0] ?? null) == 'S' %}
|
{% set isCanceled = (bookingEditContext.bookingData.participantsStatus[loop.index0] ?? null) == 'S' %}
|
||||||
|
{% set attentionLabels = bookingEditContext.missingValueLabelsByParticipantIndex[loop.index0]|default([]) %}
|
||||||
{% include 'booking/_participant_card.html.twig' with {
|
{% include 'booking/_participant_card.html.twig' with {
|
||||||
'cardData': bookingEditContext.cardsData[loop.index0],
|
'cardData': bookingEditContext.cardsData[loop.index0],
|
||||||
'index': loop.index0,
|
'index': loop.index0,
|
||||||
@@ -82,6 +89,8 @@
|
|||||||
'bookingId': bookingEditContext.bookingData.id,
|
'bookingId': bookingEditContext.bookingData.id,
|
||||||
'isCanceled': isCanceled,
|
'isCanceled': isCanceled,
|
||||||
'isSubmitted': bookingEditContext.isSubmitted,
|
'isSubmitted': bookingEditContext.isSubmitted,
|
||||||
|
'needsAttention': attentionLabels is not empty,
|
||||||
|
'attentionLabels': attentionLabels,
|
||||||
} %}
|
} %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@@ -97,13 +106,13 @@
|
|||||||
class="inline-flex items-center justify-center bg-gray-200 rounded-md w-8 h-8 md:w-10 md:h-10">
|
class="inline-flex items-center justify-center bg-gray-200 rounded-md w-8 h-8 md:w-10 md:h-10">
|
||||||
<svg class="w-6 h-6 md:w-8 md:h-8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><line x1="200" y1="56" x2="56" y2="200" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><line x1="200" y1="200" x2="56" y2="56" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg>
|
<svg class="w-6 h-6 md:w-8 md:h-8" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><line x1="200" y1="56" x2="56" y2="200" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><line x1="200" y1="200" x2="56" y2="56" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg>
|
||||||
</a>
|
</a>
|
||||||
{% if bookingEditContext.isDirty %}
|
{% if bookingEditContext.isDirty or bookingEditContext.hasBlockingValidationErrors %}
|
||||||
<button type="submit"
|
<button type="submit"
|
||||||
{% if bookingEditContext.hasValidationErrors %}
|
{% if bookingEditContext.hasBlockingValidationErrors %}
|
||||||
disabled
|
disabled
|
||||||
title="Bitte prüfe zuerst deine Eingaben"
|
title="Bitte prüfe zuerst deine Eingaben"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
class="button button--primary {{ bookingEditContext.hasValidationErrors ? 'opacity-50 cursor-not-allowed' : '' }}">
|
class="button button--primary {{ bookingEditContext.hasBlockingValidationErrors ? 'opacity-50 cursor-not-allowed' : '' }}">
|
||||||
Buchung aktualisieren
|
Buchung aktualisieren
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -6,14 +6,20 @@ namespace App\Tests\Controller\Booking\Edit;
|
|||||||
|
|
||||||
use App\BusProNet\Model\Booking;
|
use App\BusProNet\Model\Booking;
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||||
use App\Controller\Booking\Edit\IndexController;
|
use App\Controller\Booking\Edit\IndexController;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\BookingEditContext;
|
||||||
|
use App\Form\Model\BookingSummaryDto;
|
||||||
|
use App\Form\Model\ParticipantCardDataDto;
|
||||||
|
use App\Form\Model\ParticipantCardPriceDto;
|
||||||
use App\Model\BookingEditSubmissionResult;
|
use App\Model\BookingEditSubmissionResult;
|
||||||
use App\Service\BookingChangeTracker;
|
use App\Service\BookingChangeTracker;
|
||||||
use App\Service\BookingEditContextFactory;
|
use App\Service\BookingEditContextFactory;
|
||||||
use App\Service\BookingEditDataLoader;
|
use App\Service\BookingEditDataLoader;
|
||||||
use App\Service\BookingEditDraftManager;
|
use App\Service\BookingEditDraftManager;
|
||||||
|
use App\Service\BookingEditPreFlightChecker;
|
||||||
use App\Service\BookingEditSubmitter;
|
use App\Service\BookingEditSubmitter;
|
||||||
use App\Service\BookingSessionManager;
|
use App\Service\BookingSessionManager;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@@ -41,6 +47,309 @@ class IndexControllerTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testIndexShowsAttentionWarningWithoutBlockingInternalAgencyOverview(): void
|
||||||
|
{
|
||||||
|
$request = Request::create('/bookings/42/edit', 'GET');
|
||||||
|
$user = $this->createUser();
|
||||||
|
$bookingDto = $this->createBookingDto();
|
||||||
|
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||||
|
$bookingDto->participants = [
|
||||||
|
$this->createParticipant(),
|
||||||
|
$this->createParticipant(),
|
||||||
|
];
|
||||||
|
$bookingData = $this->createBooking();
|
||||||
|
|
||||||
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
$form->method('isSubmitted')->willReturn(false);
|
||||||
|
|
||||||
|
$fingerprintService = $this->createMock(BookingChangeTracker::class);
|
||||||
|
$fingerprintService->expects($this->once())
|
||||||
|
->method('isDirty')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$dataLoader = $this->createMock(BookingEditDataLoader::class);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('loadFormData')
|
||||||
|
->with($request, 42, $user)
|
||||||
|
->willReturn($bookingDto);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('fetchBookingData')
|
||||||
|
->with(42, $user)
|
||||||
|
->willReturn($bookingData);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('isDraftRestored')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$preflightChecker = $this->createMock(BookingEditPreFlightChecker::class);
|
||||||
|
$preflightChecker->expects($this->once())
|
||||||
|
->method('findMissingValueLabelsByParticipantIndex')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn([1 => ['E-Mail', 'Straße']]);
|
||||||
|
|
||||||
|
$contextFactory = $this->createMock(BookingEditContextFactory::class);
|
||||||
|
$contextFactory->expects($this->once())
|
||||||
|
->method('createOverviewContext')
|
||||||
|
->with($bookingDto, $bookingData, true, false, false, [1 => ['E-Mail', 'Straße']])
|
||||||
|
->willReturn($this->createOverviewContext($bookingDto, $bookingData, true, false, false, [1 => ['E-Mail', 'Straße']]));
|
||||||
|
|
||||||
|
$controller = new TestableIndexController(
|
||||||
|
$dataLoader,
|
||||||
|
$this->createMock(BookingEditDraftManager::class),
|
||||||
|
$this->createMock(BookingSessionManager::class),
|
||||||
|
$fingerprintService,
|
||||||
|
$contextFactory,
|
||||||
|
$preflightChecker,
|
||||||
|
$this->createMock(BookingEditSubmitter::class),
|
||||||
|
$user,
|
||||||
|
$form,
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $controller->index(42, $request);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Response::class, $response);
|
||||||
|
$this->assertSame([], $controller->flashes);
|
||||||
|
$this->assertTrue($controller->renderParameters['bookingEditContext']->isDirty);
|
||||||
|
$this->assertFalse($controller->renderParameters['bookingEditContext']->hasBlockingValidationErrors);
|
||||||
|
$this->assertSame(
|
||||||
|
[1 => ['E-Mail', 'Straße']],
|
||||||
|
$controller->renderParameters['bookingEditContext']->missingValueLabelsByParticipantIndex
|
||||||
|
);
|
||||||
|
$this->assertTrue($controller->renderParameters['bookingEditContext']->cardsData[0]->isValid);
|
||||||
|
$this->assertTrue($controller->renderParameters['bookingEditContext']->cardsData[1]->isValid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexShowsAttentionWarningWithoutBlockingNonAgencyOverview(): void
|
||||||
|
{
|
||||||
|
$request = Request::create('/bookings/42/edit', 'GET');
|
||||||
|
$user = $this->createUser();
|
||||||
|
$bookingDto = $this->createBookingDto();
|
||||||
|
$bookingDto->agencyCode = 'OTHER';
|
||||||
|
$bookingDto->participants = [
|
||||||
|
$this->createParticipant(),
|
||||||
|
$this->createParticipant(),
|
||||||
|
];
|
||||||
|
$bookingData = $this->createBooking();
|
||||||
|
|
||||||
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
$form->method('isSubmitted')->willReturn(false);
|
||||||
|
|
||||||
|
$fingerprintService = $this->createMock(BookingChangeTracker::class);
|
||||||
|
$fingerprintService->expects($this->once())
|
||||||
|
->method('isDirty')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$dataLoader = $this->createMock(BookingEditDataLoader::class);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('loadFormData')
|
||||||
|
->with($request, 42, $user)
|
||||||
|
->willReturn($bookingDto);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('fetchBookingData')
|
||||||
|
->with(42, $user)
|
||||||
|
->willReturn($bookingData);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('isDraftRestored')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$preflightChecker = $this->createMock(BookingEditPreFlightChecker::class);
|
||||||
|
$preflightChecker->expects($this->once())
|
||||||
|
->method('findMissingValueLabelsByParticipantIndex')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn([0 => ['E-Mail']]);
|
||||||
|
|
||||||
|
$contextFactory = $this->createMock(BookingEditContextFactory::class);
|
||||||
|
$contextFactory->expects($this->once())
|
||||||
|
->method('createOverviewContext')
|
||||||
|
->with($bookingDto, $bookingData, false, false, false, [0 => ['E-Mail']])
|
||||||
|
->willReturn($this->createOverviewContext($bookingDto, $bookingData, false, false, false, [0 => ['E-Mail']]));
|
||||||
|
|
||||||
|
$controller = new TestableIndexController(
|
||||||
|
$dataLoader,
|
||||||
|
$this->createMock(BookingEditDraftManager::class),
|
||||||
|
$this->createMock(BookingSessionManager::class),
|
||||||
|
$fingerprintService,
|
||||||
|
$contextFactory,
|
||||||
|
$preflightChecker,
|
||||||
|
$this->createMock(BookingEditSubmitter::class),
|
||||||
|
$user,
|
||||||
|
$form,
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $controller->index(42, $request);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Response::class, $response);
|
||||||
|
$this->assertSame([], $controller->flashes);
|
||||||
|
$this->assertFalse($controller->renderParameters['bookingEditContext']->isDirty);
|
||||||
|
$this->assertFalse($controller->renderParameters['bookingEditContext']->hasBlockingValidationErrors);
|
||||||
|
$this->assertSame(
|
||||||
|
[0 => ['E-Mail']],
|
||||||
|
$controller->renderParameters['bookingEditContext']->missingValueLabelsByParticipantIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexStillSubmitsInternalAgencyBookingsWhenOverviewIsInvalid(): void
|
||||||
|
{
|
||||||
|
$request = Request::create('/bookings/42/edit', 'POST');
|
||||||
|
$user = $this->createUser();
|
||||||
|
$bookingDto = $this->createBookingDto();
|
||||||
|
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||||
|
$bookingDto->participants = [
|
||||||
|
$this->createParticipant(),
|
||||||
|
$this->createParticipant(),
|
||||||
|
];
|
||||||
|
$bookingData = $this->createBooking();
|
||||||
|
|
||||||
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('handleRequest')
|
||||||
|
->with($request)
|
||||||
|
->willReturnSelf();
|
||||||
|
$form->method('isSubmitted')->willReturn(true);
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('isValid')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$fingerprintService = $this->createMock(BookingChangeTracker::class);
|
||||||
|
$fingerprintService->expects($this->never())
|
||||||
|
->method('isDirty');
|
||||||
|
|
||||||
|
$dataLoader = $this->createMock(BookingEditDataLoader::class);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('loadFormData')
|
||||||
|
->with($request, 42, $user)
|
||||||
|
->willReturn($bookingDto);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('fetchBookingData')
|
||||||
|
->with(42, $user)
|
||||||
|
->willReturn($bookingData);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('isDraftRestored')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$preflightChecker = $this->createMock(BookingEditPreFlightChecker::class);
|
||||||
|
$preflightChecker->expects($this->once())
|
||||||
|
->method('findMissingValueLabelsByParticipantIndex')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn([1 => ['E-Mail', 'Straße']]);
|
||||||
|
|
||||||
|
$submitter = $this->createMock(BookingEditSubmitter::class);
|
||||||
|
$submitter->expects($this->once())
|
||||||
|
->method('handleSubmission')
|
||||||
|
->with($request, $bookingDto, 42, $user)
|
||||||
|
->willReturn(new BookingEditSubmissionResult(
|
||||||
|
BookingEditSubmissionResult::STATUS_SUCCESS,
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
));
|
||||||
|
|
||||||
|
$contextFactory = $this->createMock(BookingEditContextFactory::class);
|
||||||
|
$contextFactory->expects($this->never())
|
||||||
|
->method('createOverviewContext');
|
||||||
|
|
||||||
|
$controller = new TestableIndexController(
|
||||||
|
$dataLoader,
|
||||||
|
$this->createMock(BookingEditDraftManager::class),
|
||||||
|
$this->createMock(BookingSessionManager::class),
|
||||||
|
$fingerprintService,
|
||||||
|
$contextFactory,
|
||||||
|
$preflightChecker,
|
||||||
|
$submitter,
|
||||||
|
$user,
|
||||||
|
$form,
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $controller->index(42, $request);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(RedirectResponse::class, $response);
|
||||||
|
$this->assertSame('/bookings/42/edit', $response->headers->get('Location'));
|
||||||
|
$this->assertSame(
|
||||||
|
[
|
||||||
|
['success', 'Buchung erfolgreich aktualisiert'],
|
||||||
|
['booking_edit_notice', 'Bitte ladet euch eine aktualisierte Rechnung herunter, damit ihr stets den aktuellen Stand eurer Buchung vorliegen habt.'],
|
||||||
|
],
|
||||||
|
$controller->flashes
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexBlocksNonInternalAgencyBookingsWhenOverviewIsInvalid(): void
|
||||||
|
{
|
||||||
|
$request = Request::create('/bookings/42/edit', 'POST');
|
||||||
|
$user = $this->createUser();
|
||||||
|
$bookingDto = $this->createBookingDto();
|
||||||
|
$bookingDto->agencyCode = 'OTHER';
|
||||||
|
$bookingDto->participants = [
|
||||||
|
$this->createParticipant(),
|
||||||
|
$this->createParticipant(),
|
||||||
|
];
|
||||||
|
$bookingData = $this->createBooking();
|
||||||
|
|
||||||
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('handleRequest')
|
||||||
|
->with($request)
|
||||||
|
->willReturnSelf();
|
||||||
|
$form->method('isSubmitted')->willReturn(true);
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('isValid')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$fingerprintService = $this->createMock(BookingChangeTracker::class);
|
||||||
|
$fingerprintService->expects($this->once())
|
||||||
|
->method('isDirty')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$dataLoader = $this->createMock(BookingEditDataLoader::class);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('loadFormData')
|
||||||
|
->with($request, 42, $user)
|
||||||
|
->willReturn($bookingDto);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('fetchBookingData')
|
||||||
|
->with(42, $user)
|
||||||
|
->willReturn($bookingData);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('isDraftRestored')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$preflightChecker = $this->createMock(BookingEditPreFlightChecker::class);
|
||||||
|
$preflightChecker->expects($this->once())
|
||||||
|
->method('findMissingValueLabelsByParticipantIndex')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn([0 => ['E-Mail']]);
|
||||||
|
|
||||||
|
$submitter = $this->createMock(BookingEditSubmitter::class);
|
||||||
|
$submitter->expects($this->never())
|
||||||
|
->method('handleSubmission');
|
||||||
|
|
||||||
|
$contextFactory = $this->createMock(BookingEditContextFactory::class);
|
||||||
|
$contextFactory->expects($this->once())
|
||||||
|
->method('createOverviewContext')
|
||||||
|
->with($bookingDto, $bookingData, false, true, true, [0 => ['E-Mail']])
|
||||||
|
->willReturn($this->createOverviewContext($bookingDto, $bookingData, false, true, true, [0 => ['E-Mail']]));
|
||||||
|
|
||||||
|
$controller = new TestableIndexController(
|
||||||
|
$dataLoader,
|
||||||
|
$this->createMock(BookingEditDraftManager::class),
|
||||||
|
$this->createMock(BookingSessionManager::class),
|
||||||
|
$fingerprintService,
|
||||||
|
$contextFactory,
|
||||||
|
$preflightChecker,
|
||||||
|
$submitter,
|
||||||
|
$user,
|
||||||
|
$form,
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $controller->index(42, $request);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Response::class, $response);
|
||||||
|
$this->assertSame([], $controller->flashes);
|
||||||
|
$this->assertTrue($controller->renderParameters['bookingEditContext']->hasBlockingValidationErrors);
|
||||||
|
$this->assertSame([0 => ['E-Mail']], $controller->renderParameters['bookingEditContext']->missingValueLabelsByParticipantIndex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider submissionResultProvider
|
* @dataProvider submissionResultProvider
|
||||||
*
|
*
|
||||||
@@ -119,6 +428,49 @@ class IndexControllerTest extends TestCase
|
|||||||
return $booking;
|
return $booking;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createParticipant(): \App\Form\Model\ParticipantDto
|
||||||
|
{
|
||||||
|
return new \App\Form\Model\ParticipantDto();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createOverviewContext(
|
||||||
|
BookingDto $bookingDto,
|
||||||
|
Booking $bookingData,
|
||||||
|
bool $isDirty,
|
||||||
|
bool $isSubmitted,
|
||||||
|
bool $hasBlockingValidationErrors,
|
||||||
|
array $missingValueLabelsByParticipantIndex = [],
|
||||||
|
): BookingEditContext {
|
||||||
|
return new BookingEditContext(
|
||||||
|
bookingDto: $bookingDto,
|
||||||
|
bookingData: $bookingData,
|
||||||
|
mutableData: null,
|
||||||
|
summaryData: $this->createMock(BookingSummaryDto::class),
|
||||||
|
cardsData: [
|
||||||
|
0 => new ParticipantCardDataDto(
|
||||||
|
'One',
|
||||||
|
'[email protected]',
|
||||||
|
'Room A',
|
||||||
|
new ParticipantCardPriceDto(10.0, false),
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
),
|
||||||
|
1 => new ParticipantCardDataDto(
|
||||||
|
'Two',
|
||||||
|
'[email protected]',
|
||||||
|
'Room B',
|
||||||
|
new ParticipantCardPriceDto(20.0, false),
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
),
|
||||||
|
],
|
||||||
|
missingValueLabelsByParticipantIndex: $missingValueLabelsByParticipantIndex,
|
||||||
|
isDirty: $isDirty,
|
||||||
|
isSubmitted: $isSubmitted,
|
||||||
|
hasBlockingValidationErrors: $hasBlockingValidationErrors,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int, array{0: string, 1: string}> $expectedFlashes
|
* @param array<int, array{0: string, 1: string}> $expectedFlashes
|
||||||
*/
|
*/
|
||||||
@@ -131,14 +483,15 @@ class IndexControllerTest extends TestCase
|
|||||||
$bookingDto = $this->createBookingDto();
|
$bookingDto = $this->createBookingDto();
|
||||||
$bookingData = $this->createBooking();
|
$bookingData = $this->createBooking();
|
||||||
$form = $this->createMock(FormInterface::class);
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
$fingerprintService = $this->createMock(BookingChangeTracker::class);
|
||||||
|
$fingerprintService->expects($this->never())
|
||||||
|
->method('isDirty');
|
||||||
|
|
||||||
$form->expects($this->once())
|
$form->expects($this->once())
|
||||||
->method('handleRequest')
|
->method('handleRequest')
|
||||||
->with($request)
|
->with($request)
|
||||||
->willReturnSelf();
|
->willReturnSelf();
|
||||||
$form->expects($this->once())
|
$form->method('isSubmitted')->willReturn(true);
|
||||||
->method('isSubmitted')
|
|
||||||
->willReturn(true);
|
|
||||||
$form->expects($this->once())
|
$form->expects($this->once())
|
||||||
->method('isValid')
|
->method('isValid')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
@@ -153,7 +506,14 @@ class IndexControllerTest extends TestCase
|
|||||||
->with(42, $user)
|
->with(42, $user)
|
||||||
->willReturn($bookingData);
|
->willReturn($bookingData);
|
||||||
$dataLoader->expects($this->once())
|
$dataLoader->expects($this->once())
|
||||||
->method('isDraftRestored');
|
->method('isDraftRestored')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$preflightChecker = $this->createMock(BookingEditPreFlightChecker::class);
|
||||||
|
$preflightChecker->expects($this->once())
|
||||||
|
->method('findMissingValueLabelsByParticipantIndex')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn([]);
|
||||||
|
|
||||||
$submitter = $this->createMock(BookingEditSubmitter::class);
|
$submitter = $this->createMock(BookingEditSubmitter::class);
|
||||||
$submitter->expects($this->once())
|
$submitter->expects($this->once())
|
||||||
@@ -165,8 +525,9 @@ class IndexControllerTest extends TestCase
|
|||||||
$dataLoader,
|
$dataLoader,
|
||||||
$this->createMock(BookingEditDraftManager::class),
|
$this->createMock(BookingEditDraftManager::class),
|
||||||
$this->createMock(BookingSessionManager::class),
|
$this->createMock(BookingSessionManager::class),
|
||||||
$this->createMock(BookingChangeTracker::class),
|
$fingerprintService,
|
||||||
$this->createMock(BookingEditContextFactory::class),
|
$this->createMock(BookingEditContextFactory::class),
|
||||||
|
$preflightChecker,
|
||||||
$submitter,
|
$submitter,
|
||||||
$user,
|
$user,
|
||||||
$form,
|
$form,
|
||||||
@@ -187,6 +548,11 @@ final class TestableIndexController extends IndexController
|
|||||||
*/
|
*/
|
||||||
public array $flashes = [];
|
public array $flashes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, mixed>
|
||||||
|
*/
|
||||||
|
public array $renderParameters = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var FormInterface<mixed>
|
* @var FormInterface<mixed>
|
||||||
*/
|
*/
|
||||||
@@ -201,6 +567,7 @@ final class TestableIndexController extends IndexController
|
|||||||
BookingSessionManager $bookingSessionService,
|
BookingSessionManager $bookingSessionService,
|
||||||
BookingChangeTracker $fingerprintService,
|
BookingChangeTracker $fingerprintService,
|
||||||
BookingEditContextFactory $editContextFactory,
|
BookingEditContextFactory $editContextFactory,
|
||||||
|
BookingEditPreFlightChecker $preFlightChecker,
|
||||||
BookingEditSubmitter $formSubmitter,
|
BookingEditSubmitter $formSubmitter,
|
||||||
private readonly User $user,
|
private readonly User $user,
|
||||||
FormInterface $form,
|
FormInterface $form,
|
||||||
@@ -213,6 +580,7 @@ final class TestableIndexController extends IndexController
|
|||||||
$bookingSessionService,
|
$bookingSessionService,
|
||||||
$fingerprintService,
|
$fingerprintService,
|
||||||
$editContextFactory,
|
$editContextFactory,
|
||||||
|
$preFlightChecker,
|
||||||
$formSubmitter,
|
$formSubmitter,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -253,6 +621,8 @@ final class TestableIndexController extends IndexController
|
|||||||
*/
|
*/
|
||||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||||
{
|
{
|
||||||
throw new \LogicException('Render should not be called in this test.');
|
$this->renderParameters = $parameters;
|
||||||
|
|
||||||
|
return new Response('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,259 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Controller\Booking\Edit;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Booking;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\BusProNet\ApiClient;
|
||||||
|
use App\Controller\Booking\Edit\ParticipantController;
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Form\BookingParticipantType;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\BookingEditContext;
|
||||||
|
use App\Form\Model\BookingSummaryDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Model\ParticipantEditDto;
|
||||||
|
use App\Service\BookingEditContextFactory;
|
||||||
|
use App\Service\BookingEditDataLoader;
|
||||||
|
use App\Service\BookingEditDraftManager;
|
||||||
|
use App\Service\BookingSessionManager;
|
||||||
|
use App\Service\ParticipantDataPrefiller;
|
||||||
|
use App\Service\ParticipantFormSupport;
|
||||||
|
use App\Security\Crypt;
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
|
|
||||||
|
class ParticipantControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
CarbonImmutable::setTestNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDummyTokenPrefillsParticipantInEditMode(): void
|
||||||
|
{
|
||||||
|
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 15, 14, 30));
|
||||||
|
|
||||||
|
$request = Request::create('/bookings/42/edit/participants/0', 'POST');
|
||||||
|
$user = $this->createUser();
|
||||||
|
$bookingDto = $this->createBookingDto();
|
||||||
|
$bookingData = $this->createBooking();
|
||||||
|
$participant = $bookingDto->participants[0];
|
||||||
|
$participant->lastName = ParticipantDataPrefiller::TOKEN;
|
||||||
|
|
||||||
|
$form = $this->createMock(FormInterface::class);
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('handleRequest')
|
||||||
|
->with($request)
|
||||||
|
->willReturnSelf();
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('isSubmitted')
|
||||||
|
->willReturn(true);
|
||||||
|
$form->expects($this->never())
|
||||||
|
->method('isValid');
|
||||||
|
|
||||||
|
$dataLoader = $this->createMock(BookingEditDataLoader::class);
|
||||||
|
$dataLoader->expects($this->once())
|
||||||
|
->method('fetchBookingData')
|
||||||
|
->with(42, $user)
|
||||||
|
->willReturn($bookingData);
|
||||||
|
|
||||||
|
$bookingSessionService = $this->createMock(BookingSessionManager::class);
|
||||||
|
$bookingSessionService->expects($this->once())
|
||||||
|
->method('getBookingDto')
|
||||||
|
->with($request, BookingDto::MODE_EDIT)
|
||||||
|
->willReturn($bookingDto);
|
||||||
|
$bookingSessionService->expects($this->once())
|
||||||
|
->method('saveBookingDto')
|
||||||
|
->with($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||||
|
|
||||||
|
$draftService = $this->createMock(BookingEditDraftManager::class);
|
||||||
|
$draftService->expects($this->once())
|
||||||
|
->method('saveDraft')
|
||||||
|
->with($user, 42, $bookingDto);
|
||||||
|
|
||||||
|
$prepopulationService = new ParticipantDataPrefiller(
|
||||||
|
$this->createMock(ApiClient::class),
|
||||||
|
$this->createMock(Crypt::class),
|
||||||
|
$this->createMock(LoggerInterface::class),
|
||||||
|
);
|
||||||
|
|
||||||
|
$participantFormSupportService = $this->createMock(ParticipantFormSupport::class);
|
||||||
|
$participantFormSupportService->expects($this->once())
|
||||||
|
->method('ensureParticipantExists')
|
||||||
|
->with($bookingDto, 0)
|
||||||
|
->willReturn($participant);
|
||||||
|
$participantFormSupportService->expects($this->exactly(2))
|
||||||
|
->method('createParticipantEditDto')
|
||||||
|
->with($bookingDto, 0)
|
||||||
|
->willReturn(new ParticipantEditDto($participant, $bookingDto));
|
||||||
|
$participantFormSupportService->expects($this->exactly(2))
|
||||||
|
->method('getParticipantFormOptions')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn([
|
||||||
|
'booking_context' => $bookingDto,
|
||||||
|
'body_dimension_ranges' => [
|
||||||
|
'height_min' => 100,
|
||||||
|
'height_max' => 250,
|
||||||
|
'weight_min' => 20,
|
||||||
|
'weight_max' => 200,
|
||||||
|
'shoe_size_min' => 20,
|
||||||
|
'shoe_size_max' => 55,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$summaryData = $this->createMock(BookingSummaryDto::class);
|
||||||
|
$context = new BookingEditContext($bookingDto, $bookingData, null, $summaryData);
|
||||||
|
|
||||||
|
$contextFactory = $this->createMock(BookingEditContextFactory::class);
|
||||||
|
$contextFactory->expects($this->once())
|
||||||
|
->method('prepareBookingDto')
|
||||||
|
->with($bookingDto);
|
||||||
|
$contextFactory->expects($this->once())
|
||||||
|
->method('createParticipantContext')
|
||||||
|
->with($bookingDto, $bookingData)
|
||||||
|
->willReturn($context);
|
||||||
|
|
||||||
|
$controller = new TestableParticipantController(
|
||||||
|
$dataLoader,
|
||||||
|
$draftService,
|
||||||
|
$contextFactory,
|
||||||
|
$bookingSessionService,
|
||||||
|
$prepopulationService,
|
||||||
|
$participantFormSupportService,
|
||||||
|
$user,
|
||||||
|
$form,
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $controller->editParticipant(42, 0, $request);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Response::class, $response);
|
||||||
|
$this->assertSame('booking/edit/participant.html.twig', $controller->renderTemplate);
|
||||||
|
$this->assertSame('Vorname 1', $participant->firstName);
|
||||||
|
$this->assertSame('Muster 1 14:30', $participant->lastName);
|
||||||
|
$this->assertSame('[email protected]', $participant->email);
|
||||||
|
$this->assertSame('2006-01-15', $participant->dateOfBirth?->format('Y-m-d'));
|
||||||
|
$this->assertSame(BookingParticipantType::class, $controller->createdFormTypes[0]);
|
||||||
|
$this->assertSame(BookingParticipantType::class, $controller->createdFormTypes[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createUser(): User
|
||||||
|
{
|
||||||
|
return new User('[email protected]');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createBookingDto(): BookingDto
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->id = 1234;
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 77);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->booking->id = 42;
|
||||||
|
$bookingDto->participants = [new ParticipantDto()];
|
||||||
|
$bookingDto->participants[0]->index = 0;
|
||||||
|
|
||||||
|
return $bookingDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createBooking(): Booking
|
||||||
|
{
|
||||||
|
$booking = new Booking();
|
||||||
|
$booking->id = 42;
|
||||||
|
$booking->dateId = 1234;
|
||||||
|
$booking->participantsStatus = ['F'];
|
||||||
|
|
||||||
|
return $booking;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final class TestableParticipantController extends ParticipantController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array<int, string>
|
||||||
|
*/
|
||||||
|
public array $createdFormTypes = [];
|
||||||
|
|
||||||
|
public ?string $renderTemplate = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, mixed>
|
||||||
|
*/
|
||||||
|
public array $renderParameters = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var FormInterface<mixed>
|
||||||
|
*/
|
||||||
|
private readonly FormInterface $form;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FormInterface<mixed> $form
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
BookingEditDataLoader $dataLoader,
|
||||||
|
BookingEditDraftManager $draftService,
|
||||||
|
BookingEditContextFactory $editContextFactory,
|
||||||
|
BookingSessionManager $bookingSessionService,
|
||||||
|
ParticipantDataPrefiller $prepopulationService,
|
||||||
|
ParticipantFormSupport $participantFormSupportService,
|
||||||
|
private readonly User $user,
|
||||||
|
FormInterface $form,
|
||||||
|
) {
|
||||||
|
$this->form = $form;
|
||||||
|
|
||||||
|
parent::__construct(
|
||||||
|
$dataLoader,
|
||||||
|
$draftService,
|
||||||
|
$editContextFactory,
|
||||||
|
$bookingSessionService,
|
||||||
|
$prepopulationService,
|
||||||
|
$participantFormSupportService,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getUser(): UserInterface
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return FormInterface<mixed>
|
||||||
|
*/
|
||||||
|
protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface
|
||||||
|
{
|
||||||
|
$this->createdFormTypes[] = $type;
|
||||||
|
|
||||||
|
return $this->form;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function addFlash(string $type, mixed $message): void
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $parameters
|
||||||
|
*/
|
||||||
|
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||||
|
{
|
||||||
|
return new RedirectResponse('/'.$route, $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $parameters
|
||||||
|
*/
|
||||||
|
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||||
|
{
|
||||||
|
$this->renderTemplate = $view;
|
||||||
|
$this->renderParameters = $parameters;
|
||||||
|
|
||||||
|
return new Response('');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Form;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Booking;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||||
|
use App\Form\BookingEditType;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Form\Forms;
|
||||||
|
|
||||||
|
class BookingEditTypeTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testValidationGroupsUseBookingEditForInternalAgencyBookings(): void
|
||||||
|
{
|
||||||
|
$form = $this->createForm($this->createBookingDto(true));
|
||||||
|
|
||||||
|
$validationGroups = $form->getConfig()->getOption('validation_groups');
|
||||||
|
|
||||||
|
$this->assertSame(['booking_edit'], $validationGroups($form));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testValidationGroupsRemainStrictForNonAgencyBookings(): void
|
||||||
|
{
|
||||||
|
$form = $this->createForm($this->createBookingDto(false));
|
||||||
|
|
||||||
|
$validationGroups = $form->getConfig()->getOption('validation_groups');
|
||||||
|
|
||||||
|
$this->assertSame(['booking_edit', 'strict_required'], $validationGroups($form));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createForm(BookingDto $bookingDto)
|
||||||
|
{
|
||||||
|
return Forms::createFormFactory()->create(BookingEditType::class, $bookingDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createBookingDto(bool $internalAgency): BookingDto
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->id = 123;
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 77);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->booking->id = 42;
|
||||||
|
$bookingDto->agencyCode = $internalAgency ? AgencyLoader::INTERNAL_AGENCY_CODE : 'other';
|
||||||
|
|
||||||
|
return $bookingDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Tests\Form\Model;
|
namespace App\Tests\Form\Model;
|
||||||
|
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\BusProNet\Model\Address;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@@ -87,4 +88,44 @@ class BookingDtoTest extends TestCase
|
|||||||
$this->assertSame('75', $restored->participants[0]->weight);
|
$this->assertSame('75', $restored->participants[0]->weight);
|
||||||
$this->assertSame('43', $restored->participants[0]->shoeSize);
|
$this->assertSame('43', $restored->participants[0]->shoeSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUnserializeNormalizesLegacyParticipantStringsOnLoad(): void
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->id = 42;
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->firstName = ' Max ';
|
||||||
|
$participant->lastName = ' Mustermann ';
|
||||||
|
$participant->email = ' [email protected] ';
|
||||||
|
$participant->remarksRoom = ' ';
|
||||||
|
$participant->licensePlate = ' B-AB 123 ';
|
||||||
|
$participant->purchaseVoucherCode = ' ABC-123 ';
|
||||||
|
$participant->promoVoucherCode = ' PROMO ';
|
||||||
|
$participant->address = new Address();
|
||||||
|
$participant->address->street = ' Test Street 1 ';
|
||||||
|
$participant->address->postCode = ' 12345 ';
|
||||||
|
$participant->address->city = ' Test City ';
|
||||||
|
$participant->address->country = ' DE ';
|
||||||
|
|
||||||
|
$dto = new BookingDto($travel, 1);
|
||||||
|
$dto->participants = [$participant];
|
||||||
|
|
||||||
|
$restored = unserialize(serialize($dto));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(BookingDto::class, $restored);
|
||||||
|
$this->assertSame('Max', $restored->participants[0]->firstName);
|
||||||
|
$this->assertSame('Mustermann', $restored->participants[0]->lastName);
|
||||||
|
$this->assertSame('[email protected]', $restored->participants[0]->email);
|
||||||
|
$this->assertNull($restored->participants[0]->remarksRoom);
|
||||||
|
$this->assertSame('B-AB 123', $restored->participants[0]->licensePlate);
|
||||||
|
$this->assertSame('ABC-123', $restored->participants[0]->purchaseVoucherCode);
|
||||||
|
$this->assertSame('PROMO', $restored->participants[0]->promoVoucherCode);
|
||||||
|
$this->assertSame('Test Street 1', $restored->participants[0]->address->street);
|
||||||
|
$this->assertSame('12345', $restored->participants[0]->address->postCode);
|
||||||
|
$this->assertSame('Test City', $restored->participants[0]->address->city);
|
||||||
|
$this->assertSame('DE', $restored->participants[0]->address->country);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -597,6 +597,51 @@ class ParticipantEditDtoTest extends TestCase
|
|||||||
$this->assertCount(0, $skiPassViolations, 'Ski pass validation should be skipped in edit mode');
|
$this->assertCount(0, $skiPassViolations, 'Ski pass validation should be skipped in edit mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEditSubmissionValidatesApplicantAddressOnlyForFirstParticipant(): void
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
|
||||||
|
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||||
|
|
||||||
|
$participant0 = $this->createAdultParticipant('[email protected]');
|
||||||
|
$participant0->index = 0;
|
||||||
|
$participant0->address = null;
|
||||||
|
|
||||||
|
$participant1 = $this->createAdultParticipant('[email protected]');
|
||||||
|
$participant1->index = 1;
|
||||||
|
$participant1->address = null;
|
||||||
|
|
||||||
|
$bookingDto->participants = [$participant0, $participant1];
|
||||||
|
|
||||||
|
$wrapper0 = new ParticipantEditDto(
|
||||||
|
participant: $bookingDto->participants[0],
|
||||||
|
bookingContext: $bookingDto,
|
||||||
|
);
|
||||||
|
$wrapper1 = new ParticipantEditDto(
|
||||||
|
participant: $bookingDto->participants[1],
|
||||||
|
bookingContext: $bookingDto,
|
||||||
|
);
|
||||||
|
|
||||||
|
$violations0 = $this->validator->validate($wrapper0, null, ['booking_edit', 'strict_required']);
|
||||||
|
$addressViolations0 = array_filter(
|
||||||
|
iterator_to_array($violations0),
|
||||||
|
fn ($v) => 'address' === $v->getPropertyPath() || 'participant.address' === $v->getPropertyPath()
|
||||||
|
);
|
||||||
|
|
||||||
|
$violations1 = $this->validator->validate($wrapper1, null, ['booking_edit', 'strict_required']);
|
||||||
|
$addressViolations1 = array_filter(
|
||||||
|
iterator_to_array($violations1),
|
||||||
|
fn ($v) => 'address' === $v->getPropertyPath() || 'participant.address' === $v->getPropertyPath()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertCount(1, $addressViolations0, 'Applicant address should still be required in edit submission');
|
||||||
|
$this->assertCount(0, $addressViolations1, 'Non-applicant address should not be required in edit submission');
|
||||||
|
}
|
||||||
|
|
||||||
public function testSkiPassAgeCalculatedAtTravelDate(): void
|
public function testSkiPassAgeCalculatedAtTravelDate(): void
|
||||||
{
|
{
|
||||||
$travel = new Travel();
|
$travel = new Travel();
|
||||||
@@ -635,6 +680,54 @@ class ParticipantEditDtoTest extends TestCase
|
|||||||
$this->assertCount(0, $skiPassViolations, 'Age should be calculated at travel date for baby exemption');
|
$this->assertCount(0, $skiPassViolations, 'Age should be calculated at travel date for baby exemption');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDependentWithoutInsurancePassesWhenApplicantUsesBulkInsurance(): void
|
||||||
|
{
|
||||||
|
$applicant = $this->createAdultParticipant('[email protected]');
|
||||||
|
$applicant->bulkInsuranceBooking = true;
|
||||||
|
|
||||||
|
$dependent = $this->createAdultParticipant('[email protected]');
|
||||||
|
$dependent->insurance = null;
|
||||||
|
|
||||||
|
$bookingDto = $this->createBookingDtoWithParticipants([$applicant, $dependent]);
|
||||||
|
|
||||||
|
$wrapper = new ParticipantEditDto(
|
||||||
|
participant: $bookingDto->participants[1],
|
||||||
|
bookingContext: $bookingDto,
|
||||||
|
);
|
||||||
|
|
||||||
|
$violations = $this->validator->validate($wrapper, null, ['strict_required']);
|
||||||
|
$insuranceViolations = array_filter(
|
||||||
|
iterator_to_array($violations),
|
||||||
|
fn ($v) => 'participant.insurance' === $v->getPropertyPath()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertCount(0, $insuranceViolations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDependentWithoutInsuranceFailsWhenApplicantDoesNotUseBulkInsurance(): void
|
||||||
|
{
|
||||||
|
$applicant = $this->createAdultParticipant('[email protected]');
|
||||||
|
$applicant->bulkInsuranceBooking = false;
|
||||||
|
|
||||||
|
$dependent = $this->createAdultParticipant('[email protected]');
|
||||||
|
$dependent->insurance = null;
|
||||||
|
|
||||||
|
$bookingDto = $this->createBookingDtoWithParticipants([$applicant, $dependent]);
|
||||||
|
|
||||||
|
$wrapper = new ParticipantEditDto(
|
||||||
|
participant: $bookingDto->participants[1],
|
||||||
|
bookingContext: $bookingDto,
|
||||||
|
);
|
||||||
|
|
||||||
|
$violations = $this->validator->validate($wrapper, null, ['strict_required']);
|
||||||
|
$insuranceViolations = array_filter(
|
||||||
|
iterator_to_array($violations),
|
||||||
|
fn ($v) => 'participant.insurance' === $v->getPropertyPath()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertCount(1, $insuranceViolations);
|
||||||
|
}
|
||||||
|
|
||||||
private function createBookingDtoWithParticipants(array $participants): BookingDto
|
private function createBookingDtoWithParticipants(array $participants): BookingDto
|
||||||
{
|
{
|
||||||
$travel = new Travel();
|
$travel = new Travel();
|
||||||
|
|||||||
@@ -4,14 +4,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Tests\Service;
|
namespace App\Tests\Service;
|
||||||
|
|
||||||
use App\BusProNet\Model\BaseData;
|
|
||||||
use App\BusProNet\Model\Booking;
|
use App\BusProNet\Model\Booking;
|
||||||
use App\BusProNet\Model\MutableData;
|
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\BookingEditContext;
|
|
||||||
use App\Form\Model\BookingMutabilityDto;
|
|
||||||
use App\Form\Model\BookingSummaryDto;
|
use App\Form\Model\BookingSummaryDto;
|
||||||
|
use App\Form\Model\ParticipantCardDataDto;
|
||||||
|
use App\Form\Model\ParticipantCardPriceDto;
|
||||||
use App\Service\BookingEditContextFactory;
|
use App\Service\BookingEditContextFactory;
|
||||||
use App\Service\BookingSummaryAssembler;
|
use App\Service\BookingSummaryAssembler;
|
||||||
use App\Service\ParticipantCardAssembler;
|
use App\Service\ParticipantCardAssembler;
|
||||||
@@ -20,151 +18,61 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class BookingEditContextFactoryTest extends TestCase
|
class BookingEditContextFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testPrepareBookingDtoRefreshesTravelAvailability(): void
|
public function testCreateOverviewContextKeepsCardsNeutralAndTracksMissingValueLabels(): void
|
||||||
{
|
{
|
||||||
$travel = new Travel();
|
$travel = new Travel();
|
||||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
$travel->id = 123;
|
||||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
|
||||||
$bookingDto = new BookingDto($travel, 157047);
|
|
||||||
|
|
||||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
$travelDataService->expects($this->once())
|
$bookingDto->participants = [
|
||||||
->method('enrichWithFreshAvailabilities')
|
new \App\Form\Model\ParticipantDto(),
|
||||||
->with($travel);
|
new \App\Form\Model\ParticipantDto(),
|
||||||
|
];
|
||||||
$service = new BookingEditContextFactory(
|
|
||||||
$this->createMock(ParticipantCardAssembler::class),
|
|
||||||
$this->createMock(BookingSummaryAssembler::class),
|
|
||||||
$travelDataService,
|
|
||||||
);
|
|
||||||
|
|
||||||
$service->prepareBookingDto($bookingDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCreateBuildsEditContext(): void
|
|
||||||
{
|
|
||||||
$travel = new Travel();
|
|
||||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
|
||||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
|
||||||
|
|
||||||
$bookingDto = new BookingDto($travel, 157047);
|
|
||||||
$bookingDto->booking = new Booking();
|
|
||||||
|
|
||||||
$bookingData = new Booking();
|
$bookingData = new Booking();
|
||||||
$bookingData->dateId = 1234;
|
$bookingData->dateId = 123;
|
||||||
|
|
||||||
$mutableData = new BaseData([
|
|
||||||
MutableData::CATEGORY_ADDITIONAL_SERVICES => new MutableData(MutableData::CATEGORY_ADDITIONAL_SERVICES, true, new \DateTimeImmutable('2030-01-02')),
|
|
||||||
]);
|
|
||||||
$summaryData = $this->createMock(BookingSummaryDto::class);
|
$summaryData = $this->createMock(BookingSummaryDto::class);
|
||||||
|
|
||||||
$summaryDataService = $this->createMock(BookingSummaryAssembler::class);
|
$participantCardAssembler = $this->createMock(ParticipantCardAssembler::class);
|
||||||
$summaryDataService->expects($this->once())
|
$participantCardAssembler->expects($this->once())
|
||||||
->method('getSummaryData')
|
|
||||||
->with($bookingDto)
|
|
||||||
->willReturn($summaryData);
|
|
||||||
|
|
||||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
|
||||||
$travelDataService->expects($this->once())
|
|
||||||
->method('getMutabilityData')
|
|
||||||
->with(1234)
|
|
||||||
->willReturn($mutableData);
|
|
||||||
|
|
||||||
$service = new BookingEditContextFactory(
|
|
||||||
$this->createMock(ParticipantCardAssembler::class),
|
|
||||||
$summaryDataService,
|
|
||||||
$travelDataService,
|
|
||||||
);
|
|
||||||
|
|
||||||
$context = $service->createParticipantContext($bookingDto, $bookingData);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(BookingEditContext::class, $context);
|
|
||||||
$this->assertSame($bookingDto, $context->bookingDto);
|
|
||||||
$this->assertSame($bookingData, $context->bookingData);
|
|
||||||
$this->assertInstanceOf(BookingMutabilityDto::class, $context->mutableData);
|
|
||||||
$this->assertSame($mutableData->getItemByKey(MutableData::CATEGORY_ADDITIONAL_SERVICES), $context->mutableData->additionalServices);
|
|
||||||
$this->assertNull($context->mutableData->transportation);
|
|
||||||
$this->assertSame($summaryData, $context->summaryData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCreateParticipantContextWithoutBookingDataFallsBackToSummaryOnly(): void
|
|
||||||
{
|
|
||||||
$travel = new Travel();
|
|
||||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
|
||||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
|
||||||
|
|
||||||
$bookingDto = new BookingDto($travel, 157047);
|
|
||||||
$summaryData = $this->createMock(BookingSummaryDto::class);
|
|
||||||
|
|
||||||
$summaryDataService = $this->createMock(BookingSummaryAssembler::class);
|
|
||||||
$summaryDataService->expects($this->once())
|
|
||||||
->method('getSummaryData')
|
|
||||||
->with($bookingDto)
|
|
||||||
->willReturn($summaryData);
|
|
||||||
|
|
||||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
|
||||||
$travelDataService->expects($this->never())
|
|
||||||
->method('getMutabilityData');
|
|
||||||
|
|
||||||
$service = new BookingEditContextFactory(
|
|
||||||
$this->createMock(ParticipantCardAssembler::class),
|
|
||||||
$summaryDataService,
|
|
||||||
$travelDataService,
|
|
||||||
);
|
|
||||||
|
|
||||||
$context = $service->createParticipantContext($bookingDto, null);
|
|
||||||
|
|
||||||
$this->assertInstanceOf(BookingEditContext::class, $context);
|
|
||||||
$this->assertSame($bookingDto, $context->bookingDto);
|
|
||||||
$this->assertNull($context->bookingData);
|
|
||||||
$this->assertNull($context->mutableData);
|
|
||||||
$this->assertSame($summaryData, $context->summaryData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCreateOverviewContextBuildsEditOverviewPayload(): void
|
|
||||||
{
|
|
||||||
$travel = new Travel();
|
|
||||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
|
||||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
|
||||||
|
|
||||||
$bookingDto = new BookingDto($travel, 157047);
|
|
||||||
$bookingData = new Booking();
|
|
||||||
$bookingData->dateId = 1234;
|
|
||||||
|
|
||||||
$mutableData = new BaseData([]);
|
|
||||||
$summaryData = $this->createMock(BookingSummaryDto::class);
|
|
||||||
$cardsData = [];
|
|
||||||
|
|
||||||
$participantCardDataService = $this->createMock(ParticipantCardAssembler::class);
|
|
||||||
$participantCardDataService->expects($this->once())
|
|
||||||
->method('getAllCardsDataWithValidation')
|
->method('getAllCardsDataWithValidation')
|
||||||
->with($bookingDto)
|
->with($bookingDto)
|
||||||
->willReturn($cardsData);
|
->willReturn([
|
||||||
|
0 => new ParticipantCardDataDto('One', '[email protected]', 'Room A', new ParticipantCardPriceDto(10.0, false), false, true),
|
||||||
|
1 => new ParticipantCardDataDto('Two', '[email protected]', 'Room B', new ParticipantCardPriceDto(20.0, false), false, true),
|
||||||
|
]);
|
||||||
|
|
||||||
$summaryDataService = $this->createMock(BookingSummaryAssembler::class);
|
$summaryAssembler = $this->createMock(BookingSummaryAssembler::class);
|
||||||
$summaryDataService->expects($this->once())
|
$summaryAssembler->expects($this->once())
|
||||||
->method('getSummaryData')
|
->method('getSummaryData')
|
||||||
->with($bookingDto)
|
->with($bookingDto)
|
||||||
->willReturn($summaryData);
|
->willReturn($summaryData);
|
||||||
|
|
||||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
$travelDataProvider = $this->createMock(TravelDataProvider::class);
|
||||||
$travelDataService->expects($this->once())
|
$travelDataProvider->expects($this->once())
|
||||||
->method('getMutabilityData')
|
->method('getMutabilityData')
|
||||||
->with(1234)
|
->with(123)
|
||||||
->willReturn($mutableData);
|
->willReturn(null);
|
||||||
|
|
||||||
$service = new BookingEditContextFactory(
|
$factory = new BookingEditContextFactory(
|
||||||
$participantCardDataService,
|
$participantCardAssembler,
|
||||||
$summaryDataService,
|
$summaryAssembler,
|
||||||
$travelDataService,
|
$travelDataProvider,
|
||||||
);
|
);
|
||||||
|
|
||||||
$context = $service->createOverviewContext($bookingDto, $bookingData, true, false, true);
|
$context = $factory->createOverviewContext(
|
||||||
|
$bookingDto,
|
||||||
|
$bookingData,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
[1 => ['E-Mail', 'Straße']],
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertInstanceOf(BookingEditContext::class, $context);
|
$this->assertTrue($context->cardsData[0]->isValid);
|
||||||
$this->assertSame($cardsData, $context->cardsData);
|
$this->assertTrue($context->cardsData[1]->isValid);
|
||||||
$this->assertTrue($context->isDirty);
|
$this->assertSame([], $context->cardsData[1]->errorMessages);
|
||||||
$this->assertFalse($context->isSubmitted);
|
$this->assertSame([1 => ['E-Mail', 'Straße']], $context->missingValueLabelsByParticipantIndex);
|
||||||
$this->assertTrue($context->hasValidationErrors);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,341 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Tests\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\CrmSelection;
|
||||||
|
use App\BusProNet\Model\CrmSelectionGroup;
|
||||||
|
use App\BusProNet\Model\Address;
|
||||||
|
use App\BusProNet\Model\Booking;
|
||||||
|
use App\BusProNet\Model\Service;
|
||||||
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||||
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Service\BookingEditPreFlightChecker;
|
||||||
|
use App\Service\BookingPriceCalculator;
|
||||||
|
use App\Service\ParticipantEligibilityChecker;
|
||||||
|
use App\Service\VoucherValidator;
|
||||||
|
use App\Form\Service\ServiceAgeEvaluator;
|
||||||
|
use App\Validator\Constraints\MandatoryAdditionalServicesSelectedValidator;
|
||||||
|
use App\Validator\Constraints\PromoVoucherValidator;
|
||||||
|
use App\Validator\Constraints\PurchaseVoucherValidator;
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\Constraints\Email;
|
||||||
|
use Symfony\Component\Validator\Constraints\EmailValidator;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidatorInterface;
|
||||||
|
use Symfony\Component\Validator\Validation;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
class BookingEditPreFlightCheckerTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
CarbonImmutable::setTestNow(CarbonImmutable::create(2025, 6, 1, 12, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
CarbonImmutable::setTestNow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanAttentionReturnsMissingValueLabelsForParticipantsThatNeedAttention(): void
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = CarbonImmutable::now()->addMonth()->toDateTimeImmutable();
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||||
|
|
||||||
|
$bookingDto->participants = [
|
||||||
|
$this->createCompleteParticipant(0),
|
||||||
|
$this->createInternalAgencyParticipantNeedingAttention(1),
|
||||||
|
];
|
||||||
|
|
||||||
|
$checker = new BookingEditPreFlightChecker($this->createValidator());
|
||||||
|
|
||||||
|
$result = $checker->findMissingValueLabelsByParticipantIndex($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[1 => ['Vorname', 'Nachname', 'E-Mail']],
|
||||||
|
$result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanAttentionDoesNotFlagMissingAddressForNonApplicantParticipantsInNonInternalAgencyEdit(): void
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = CarbonImmutable::now()->addMonth()->toDateTimeImmutable();
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->agencyCode = 'OTHER';
|
||||||
|
|
||||||
|
$bookingDto->participants = [
|
||||||
|
$this->createCompleteParticipant(0),
|
||||||
|
$this->createParticipantWithMissingAddressOnly(1),
|
||||||
|
];
|
||||||
|
|
||||||
|
$checker = new BookingEditPreFlightChecker($this->createValidator());
|
||||||
|
|
||||||
|
$result = $checker->findMissingValueLabelsByParticipantIndex($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanAttentionIgnoresBlankBodyDimensionsEvenWhenRentalsAreSelected(): void
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = CarbonImmutable::now()->addMonth()->toDateTimeImmutable();
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||||
|
|
||||||
|
$participant = $this->createCompleteParticipant(0);
|
||||||
|
$participant->rentals = [$this->createRentalService()];
|
||||||
|
$participant->height = null;
|
||||||
|
$participant->weight = null;
|
||||||
|
$participant->shoeSize = null;
|
||||||
|
|
||||||
|
$bookingDto->participants = [$participant];
|
||||||
|
|
||||||
|
$checker = new BookingEditPreFlightChecker($this->createValidator());
|
||||||
|
|
||||||
|
$result = $checker->findMissingValueLabelsByParticipantIndex($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanAttentionShowsBodyDimensionLabelsWhenProvidedValuesAreOutOfRange(): void
|
||||||
|
{
|
||||||
|
$bookingDto = $this->createBookingDto(true);
|
||||||
|
$participant = $this->createCompleteParticipant(0);
|
||||||
|
$participant->rentals = [$this->createRentalService()];
|
||||||
|
$participant->height = '999';
|
||||||
|
$participant->weight = '999';
|
||||||
|
$participant->shoeSize = '999';
|
||||||
|
|
||||||
|
$bookingDto->participants = [$participant];
|
||||||
|
|
||||||
|
$checker = new BookingEditPreFlightChecker($this->createValidator());
|
||||||
|
|
||||||
|
$result = $checker->findMissingValueLabelsByParticipantIndex($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[0 => ['Körpergröße', 'Gewicht', 'Schuhgröße']],
|
||||||
|
$result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanAttentionSuppressesOutOfRangeBodyDimensionLabelsWhenSelection1475Applies(): void
|
||||||
|
{
|
||||||
|
$bookingDto = $this->createBookingDto(true, [1475]);
|
||||||
|
$participant = $this->createCompleteParticipant(0);
|
||||||
|
$participant->rentals = [$this->createRentalService()];
|
||||||
|
$participant->height = '999';
|
||||||
|
$participant->weight = '999';
|
||||||
|
$participant->shoeSize = '999';
|
||||||
|
|
||||||
|
$bookingDto->participants = [$participant];
|
||||||
|
|
||||||
|
$checker = new BookingEditPreFlightChecker($this->createValidator());
|
||||||
|
|
||||||
|
$result = $checker->findMissingValueLabelsByParticipantIndex($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame([], $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanAttentionShowsPickupAndDropOffLabelsWhenBusTransportRequiresThem(): void
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = CarbonImmutable::now()->addMonth()->toDateTimeImmutable();
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||||
|
|
||||||
|
$participant = $this->createCompleteParticipant(0);
|
||||||
|
$participant->transportationOutbound = $this->createBusService();
|
||||||
|
$participant->transportationInbound = $this->createBusService();
|
||||||
|
$participant->differentDropOff = true;
|
||||||
|
$participant->pickup = null;
|
||||||
|
$participant->dropOff = null;
|
||||||
|
|
||||||
|
$bookingDto->participants = [$participant];
|
||||||
|
|
||||||
|
$checker = new BookingEditPreFlightChecker($this->createValidator());
|
||||||
|
|
||||||
|
$result = $checker->findMissingValueLabelsByParticipantIndex($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[0 => ['Zustieg', 'Ausstieg']],
|
||||||
|
$result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createCompleteParticipant(int $index): ParticipantDto
|
||||||
|
{
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = $index;
|
||||||
|
$participant->firstName = 'Max';
|
||||||
|
$participant->lastName = 'Mustermann';
|
||||||
|
$participant->gender = 'M';
|
||||||
|
$participant->nationality = 'D';
|
||||||
|
$participant->dateOfBirth = new \DateTimeImmutable('1990-01-01');
|
||||||
|
$participant->email = '[email protected]';
|
||||||
|
$participant->assignedRoomId = 1;
|
||||||
|
$participant->transportationOutbound = $this->createTransportService();
|
||||||
|
$participant->transportationInbound = $this->createTransportService();
|
||||||
|
$participant->address = new Address();
|
||||||
|
$participant->address->street = 'Test Street 1';
|
||||||
|
$participant->address->postCode = '12345';
|
||||||
|
$participant->address->city = 'Test City';
|
||||||
|
$participant->address->country = 'DE';
|
||||||
|
|
||||||
|
return $participant;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createInternalAgencyParticipantNeedingAttention(int $index): ParticipantDto
|
||||||
|
{
|
||||||
|
$participant = $this->createCompleteParticipant($index);
|
||||||
|
$participant->firstName = null;
|
||||||
|
$participant->lastName = null;
|
||||||
|
$participant->email = null;
|
||||||
|
$participant->address->street = null;
|
||||||
|
|
||||||
|
return $participant;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createParticipantWithMissingAddressOnly(int $index): ParticipantDto
|
||||||
|
{
|
||||||
|
$participant = $this->createCompleteParticipant($index);
|
||||||
|
$participant->email = sprintf('other%[email protected]', $index);
|
||||||
|
$participant->address = new Address();
|
||||||
|
|
||||||
|
return $participant;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTransportService(): Service
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->subType = 'TRAIN';
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createBusService(): Service
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->subType = 'BUS';
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createRentalService(): Service
|
||||||
|
{
|
||||||
|
$service = new Service();
|
||||||
|
$service->subType = 'VER';
|
||||||
|
|
||||||
|
return $service;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createValidator(): ValidatorInterface
|
||||||
|
{
|
||||||
|
$voucherValidator = $this->createMock(VoucherValidator::class);
|
||||||
|
$bookingPriceCalculator = $this->createMock(BookingPriceCalculator::class);
|
||||||
|
$participantEligibilityChecker = $this->createMock(ParticipantEligibilityChecker::class);
|
||||||
|
$participantEligibilityChecker
|
||||||
|
->method('isParticipantEligible')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$validatorFactory = new class(
|
||||||
|
$voucherValidator,
|
||||||
|
$bookingPriceCalculator,
|
||||||
|
$participantEligibilityChecker,
|
||||||
|
new ServiceAgeEvaluator(),
|
||||||
|
) implements ConstraintValidatorFactoryInterface {
|
||||||
|
public function __construct(
|
||||||
|
private readonly VoucherValidator $voucherValidator,
|
||||||
|
private readonly BookingPriceCalculator $bookingPriceCalculator,
|
||||||
|
private readonly ParticipantEligibilityChecker $participantEligibilityChecker,
|
||||||
|
private readonly ServiceAgeEvaluator $serviceAgeEvaluator,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInstance(Constraint $constraint): ConstraintValidatorInterface
|
||||||
|
{
|
||||||
|
$className = $constraint->validatedBy();
|
||||||
|
|
||||||
|
if (EmailValidator::class === $className) {
|
||||||
|
return new EmailValidator(Email::VALIDATION_MODE_HTML5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PurchaseVoucherValidator::class === $className) {
|
||||||
|
return new PurchaseVoucherValidator($this->voucherValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PromoVoucherValidator::class === $className) {
|
||||||
|
return new PromoVoucherValidator($this->voucherValidator, $this->bookingPriceCalculator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MandatoryAdditionalServicesSelectedValidator::class === $className) {
|
||||||
|
return new MandatoryAdditionalServicesSelectedValidator(
|
||||||
|
$this->participantEligibilityChecker,
|
||||||
|
$this->serviceAgeEvaluator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new $className();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Validation::createValidatorBuilder()
|
||||||
|
->enableAttributeMapping()
|
||||||
|
->setConstraintValidatorFactory($validatorFactory)
|
||||||
|
->getValidator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<int> $selectionIds
|
||||||
|
*/
|
||||||
|
private function createBookingDto(bool $internalAgency, array $selectionIds = []): BookingDto
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->dateFrom = CarbonImmutable::now()->addMonth()->toDateTimeImmutable();
|
||||||
|
$this->applySelectionIds($travel, $selectionIds);
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->booking = new Booking();
|
||||||
|
$bookingDto->agencyCode = $internalAgency ? AgencyLoader::INTERNAL_AGENCY_CODE : 'OTHER';
|
||||||
|
|
||||||
|
return $bookingDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<int> $selectionIds
|
||||||
|
*/
|
||||||
|
private function applySelectionIds(Travel $travel, array $selectionIds): void
|
||||||
|
{
|
||||||
|
if ([] === $selectionIds) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$group = new CrmSelectionGroup();
|
||||||
|
$group->id = 1;
|
||||||
|
$group->selections = [];
|
||||||
|
|
||||||
|
foreach ($selectionIds as $selectionId) {
|
||||||
|
$selection = new CrmSelection();
|
||||||
|
$selection->id = $selectionId;
|
||||||
|
$group->selections[] = $selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
$travel->selectionGroups = [1 => $group];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,10 +7,14 @@ namespace App\Tests\Service;
|
|||||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||||
use Symfony\Component\Validator\ConstraintViolationList;
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
use App\BusProNet\Model\Booking;
|
||||||
use App\BusProNet\Model\Room;
|
use App\BusProNet\Model\Room;
|
||||||
|
use App\BusProNet\Model\Surcharge;
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
|
use App\Form\Model\ParticipantEditDto;
|
||||||
use App\Service\BookingPriceCalculator;
|
use App\Service\BookingPriceCalculator;
|
||||||
use App\Service\ParticipantCardAssembler;
|
use App\Service\ParticipantCardAssembler;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
@@ -278,7 +282,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
|||||||
|
|
||||||
// Mock price calculation
|
// Mock price calculation
|
||||||
$this->priceCalculator
|
$this->priceCalculator
|
||||||
->expects($this->exactly(3))
|
->expects($this->once())
|
||||||
->method('calculateAllParticipantIndividualPrices')
|
->method('calculateAllParticipantIndividualPrices')
|
||||||
->with($bookingDto)
|
->with($bookingDto)
|
||||||
->willReturn([450.0, 500.0, 480.0]);
|
->willReturn([450.0, 500.0, 480.0]);
|
||||||
@@ -306,6 +310,50 @@ class ParticipantCardAssemblerTest extends TestCase
|
|||||||
$this->assertFalse($result[2]->price->showDash);
|
$this->assertFalse($result[2]->price->showDash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetAllCardsDataUsesCanceledSurchargesBeforePrecomputedActivePrices(): void
|
||||||
|
{
|
||||||
|
$room = new Room();
|
||||||
|
$room->id = 1;
|
||||||
|
$room->label = 'Doppelzimmer';
|
||||||
|
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->rooms = [$room];
|
||||||
|
|
||||||
|
$activeParticipant = new ParticipantDto();
|
||||||
|
$activeParticipant->firstName = 'Max';
|
||||||
|
$activeParticipant->lastName = 'Mustermann';
|
||||||
|
$activeParticipant->assignedRoomId = 1;
|
||||||
|
|
||||||
|
$canceledParticipant = new ParticipantDto();
|
||||||
|
$canceledParticipant->firstName = 'Anna';
|
||||||
|
$canceledParticipant->lastName = 'Schmidt';
|
||||||
|
$canceledParticipant->assignedRoomId = 1;
|
||||||
|
|
||||||
|
$surcharge = new Surcharge();
|
||||||
|
$surcharge->mapping = [1];
|
||||||
|
$surcharge->individualPrice = [1 => 75.0];
|
||||||
|
|
||||||
|
$booking = new Booking();
|
||||||
|
$booking->participantsStatus = [0 => 'A', 1 => 'S'];
|
||||||
|
$booking->surcharges = [$surcharge];
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->booking = $booking;
|
||||||
|
$bookingDto->participants = [$activeParticipant, $canceledParticipant];
|
||||||
|
|
||||||
|
$this->priceCalculator
|
||||||
|
->expects($this->once())
|
||||||
|
->method('calculateAllParticipantIndividualPrices')
|
||||||
|
->with($bookingDto)
|
||||||
|
->willReturn([0 => 450.0, 1 => 999.0]);
|
||||||
|
|
||||||
|
$result = $this->service->getAllCardsData($bookingDto);
|
||||||
|
|
||||||
|
$this->assertSame(450.0, $result[0]->price->amount);
|
||||||
|
$this->assertSame(75.0, $result[1]->price->amount);
|
||||||
|
$this->assertFalse($result[1]->price->showDash);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetAllCardsDataWithEmptyParticipants(): void
|
public function testGetAllCardsDataWithEmptyParticipants(): void
|
||||||
{
|
{
|
||||||
$travel = new Travel();
|
$travel = new Travel();
|
||||||
@@ -471,7 +519,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
|||||||
$bookingDto->participants = [$participant1, $participant2];
|
$bookingDto->participants = [$participant1, $participant2];
|
||||||
|
|
||||||
$this->priceCalculator
|
$this->priceCalculator
|
||||||
->expects($this->exactly(2))
|
->expects($this->once())
|
||||||
->method('calculateAllParticipantIndividualPrices')
|
->method('calculateAllParticipantIndividualPrices')
|
||||||
->willReturn([450.0, 500.0]);
|
->willReturn([450.0, 500.0]);
|
||||||
|
|
||||||
@@ -494,4 +542,48 @@ class ParticipantCardAssemblerTest extends TestCase
|
|||||||
$this->assertSame('Max Mustermann', $result[0]->name);
|
$this->assertSame('Max Mustermann', $result[0]->name);
|
||||||
$this->assertSame('Anna Schmidt', $result[1]->name);
|
$this->assertSame('Anna Schmidt', $result[1]->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetCardDataWithValidationCanForceStrictRequiredInEditMode(): void
|
||||||
|
{
|
||||||
|
$travel = new Travel();
|
||||||
|
$travel->rooms = [];
|
||||||
|
|
||||||
|
$participant = new ParticipantDto();
|
||||||
|
$participant->index = 0;
|
||||||
|
$participant->firstName = null;
|
||||||
|
$participant->lastName = 'Mustermann';
|
||||||
|
$participant->email = '[email protected]';
|
||||||
|
|
||||||
|
$bookingDto = new BookingDto($travel, 1);
|
||||||
|
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||||
|
$bookingDto->booking = new \App\BusProNet\Model\Booking();
|
||||||
|
$bookingDto->participants = [$participant];
|
||||||
|
|
||||||
|
$this->priceCalculator
|
||||||
|
->method('calculateAllParticipantIndividualPrices')
|
||||||
|
->willReturn([0.0]);
|
||||||
|
|
||||||
|
$violation = $this->createMock(ConstraintViolationInterface::class);
|
||||||
|
$violation->expects($this->once())
|
||||||
|
->method('getMessage')
|
||||||
|
->willReturn('Bitte angeben');
|
||||||
|
|
||||||
|
$violations = new ConstraintViolationList([$violation]);
|
||||||
|
|
||||||
|
$this->validator
|
||||||
|
->expects($this->once())
|
||||||
|
->method('validate')
|
||||||
|
->with(
|
||||||
|
$this->isInstanceOf(\App\Form\Model\ParticipantEditDto::class),
|
||||||
|
null,
|
||||||
|
['booking_edit', 'strict_required']
|
||||||
|
)
|
||||||
|
->willReturn($violations);
|
||||||
|
|
||||||
|
$result = $this->service->getCardDataWithValidation($bookingDto, 0, true);
|
||||||
|
|
||||||
|
$this->assertFalse($result->isValid);
|
||||||
|
$this->assertSame(['Bitte angeben'], $result->errorMessages);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -254,13 +254,13 @@ class ParticipantDataPrefillerTest extends TestCase
|
|||||||
$this->assertFalse($this->service->shouldPrefillApplicant($filled));
|
$this->assertFalse($this->service->shouldPrefillApplicant($filled));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDummyTokenMatchesOnlyInCreateMode(): void
|
public function testDummyTokenMatchesInCreateAndEditModes(): void
|
||||||
{
|
{
|
||||||
$participant = new ParticipantDto();
|
$participant = new ParticipantDto();
|
||||||
$participant->lastName = ParticipantDataPrefiller::TOKEN;
|
$participant->lastName = ParticipantDataPrefiller::TOKEN;
|
||||||
|
|
||||||
$this->assertTrue($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_CREATE));
|
$this->assertTrue($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_CREATE));
|
||||||
$this->assertFalse($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_EDIT));
|
$this->assertTrue($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_EDIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFillDummyParticipantSetsGeneratedData(): void
|
public function testFillDummyParticipantSetsGeneratedData(): void
|
||||||
|
|||||||
Reference in New Issue
Block a user