feat: pre-flight check of agency bookings

addresses #869bqxr4q
This commit is contained in:
Björn Fromme
2026-07-10 14:33:09 +02:00
parent f9142e3080
commit b41b19d4c6
26 changed files with 1818 additions and 304 deletions
@@ -6,14 +6,20 @@ namespace App\Tests\Controller\Booking\Edit;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\AgencyLoader;
use App\Controller\Booking\Edit\IndexController;
use App\Entity\User;
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\Service\BookingChangeTracker;
use App\Service\BookingEditContextFactory;
use App\Service\BookingEditDataLoader;
use App\Service\BookingEditDraftManager;
use App\Service\BookingEditPreFlightChecker;
use App\Service\BookingEditSubmitter;
use App\Service\BookingSessionManager;
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
*
@@ -119,6 +428,49 @@ class IndexControllerTest extends TestCase
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
*/
@@ -131,14 +483,15 @@ class IndexControllerTest extends TestCase
$bookingDto = $this->createBookingDto();
$bookingData = $this->createBooking();
$form = $this->createMock(FormInterface::class);
$fingerprintService = $this->createMock(BookingChangeTracker::class);
$fingerprintService->expects($this->never())
->method('isDirty');
$form->expects($this->once())
->method('handleRequest')
->with($request)
->willReturnSelf();
$form->expects($this->once())
->method('isSubmitted')
->willReturn(true);
$form->method('isSubmitted')->willReturn(true);
$form->expects($this->once())
->method('isValid')
->willReturn(true);
@@ -153,7 +506,14 @@ class IndexControllerTest extends TestCase
->with(42, $user)
->willReturn($bookingData);
$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->expects($this->once())
@@ -165,8 +525,9 @@ class IndexControllerTest extends TestCase
$dataLoader,
$this->createMock(BookingEditDraftManager::class),
$this->createMock(BookingSessionManager::class),
$this->createMock(BookingChangeTracker::class),
$fingerprintService,
$this->createMock(BookingEditContextFactory::class),
$preflightChecker,
$submitter,
$user,
$form,
@@ -187,6 +548,11 @@ final class TestableIndexController extends IndexController
*/
public array $flashes = [];
/**
* @var array<string, mixed>
*/
public array $renderParameters = [];
/**
* @var FormInterface<mixed>
*/
@@ -201,6 +567,7 @@ final class TestableIndexController extends IndexController
BookingSessionManager $bookingSessionService,
BookingChangeTracker $fingerprintService,
BookingEditContextFactory $editContextFactory,
BookingEditPreFlightChecker $preFlightChecker,
BookingEditSubmitter $formSubmitter,
private readonly User $user,
FormInterface $form,
@@ -213,6 +580,7 @@ final class TestableIndexController extends IndexController
$bookingSessionService,
$fingerprintService,
$editContextFactory,
$preFlightChecker,
$formSubmitter,
);
}
@@ -253,6 +621,8 @@ final class TestableIndexController extends IndexController
*/
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('');
}
}
+52
View File
@@ -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;
}
}
+41
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Tests\Form\Model;
use App\BusProNet\Model\Travel;
use App\BusProNet\Model\Address;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use PHPUnit\Framework\TestCase;
@@ -87,4 +88,44 @@ class BookingDtoTest extends TestCase
$this->assertSame('75', $restored->participants[0]->weight);
$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');
}
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
{
$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');
}
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
{
$travel = new Travel();
+38 -130
View File
@@ -4,14 +4,12 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Model\BaseData;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\MutableData;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\BookingEditContext;
use App\Form\Model\BookingMutabilityDto;
use App\Form\Model\BookingSummaryDto;
use App\Form\Model\ParticipantCardDataDto;
use App\Form\Model\ParticipantCardPriceDto;
use App\Service\BookingEditContextFactory;
use App\Service\BookingSummaryAssembler;
use App\Service\ParticipantCardAssembler;
@@ -20,151 +18,61 @@ use PHPUnit\Framework\TestCase;
class BookingEditContextFactoryTest extends TestCase
{
public function testPrepareBookingDtoRefreshesTravelAvailability(): void
public function testCreateOverviewContextKeepsCardsNeutralAndTracksMissingValueLabels(): void
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
$bookingDto = new BookingDto($travel, 157047);
$travel->id = 123;
$travelDataService = $this->createMock(TravelDataProvider::class);
$travelDataService->expects($this->once())
->method('enrichWithFreshAvailabilities')
->with($travel);
$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();
$bookingDto = new BookingDto($travel, 1);
$bookingDto->participants = [
new \App\Form\Model\ParticipantDto(),
new \App\Form\Model\ParticipantDto(),
];
$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);
$summaryDataService = $this->createMock(BookingSummaryAssembler::class);
$summaryDataService->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())
$participantCardAssembler = $this->createMock(ParticipantCardAssembler::class);
$participantCardAssembler->expects($this->once())
->method('getAllCardsDataWithValidation')
->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);
$summaryDataService->expects($this->once())
$summaryAssembler = $this->createMock(BookingSummaryAssembler::class);
$summaryAssembler->expects($this->once())
->method('getSummaryData')
->with($bookingDto)
->willReturn($summaryData);
$travelDataService = $this->createMock(TravelDataProvider::class);
$travelDataService->expects($this->once())
$travelDataProvider = $this->createMock(TravelDataProvider::class);
$travelDataProvider->expects($this->once())
->method('getMutabilityData')
->with(1234)
->willReturn($mutableData);
->with(123)
->willReturn(null);
$service = new BookingEditContextFactory(
$participantCardDataService,
$summaryDataService,
$travelDataService,
$factory = new BookingEditContextFactory(
$participantCardAssembler,
$summaryAssembler,
$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->assertSame($cardsData, $context->cardsData);
$this->assertTrue($context->isDirty);
$this->assertFalse($context->isSubmitted);
$this->assertTrue($context->hasValidationErrors);
$this->assertTrue($context->cardsData[0]->isValid);
$this->assertTrue($context->cardsData[1]->isValid);
$this->assertSame([], $context->cardsData[1]->errorMessages);
$this->assertSame([1 => ['E-Mail', 'Straße']], $context->missingValueLabelsByParticipantIndex);
}
}
@@ -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];
}
}
+94 -2
View File
@@ -7,10 +7,14 @@ namespace App\Tests\Service;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\ConstraintViolationList;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Room;
use App\BusProNet\Model\Surcharge;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\AgencyLoader;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Model\ParticipantEditDto;
use App\Service\BookingPriceCalculator;
use App\Service\ParticipantCardAssembler;
use PHPUnit\Framework\TestCase;
@@ -278,7 +282,7 @@ class ParticipantCardAssemblerTest extends TestCase
// Mock price calculation
$this->priceCalculator
->expects($this->exactly(3))
->expects($this->once())
->method('calculateAllParticipantIndividualPrices')
->with($bookingDto)
->willReturn([450.0, 500.0, 480.0]);
@@ -306,6 +310,50 @@ class ParticipantCardAssemblerTest extends TestCase
$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
{
$travel = new Travel();
@@ -471,7 +519,7 @@ class ParticipantCardAssemblerTest extends TestCase
$bookingDto->participants = [$participant1, $participant2];
$this->priceCalculator
->expects($this->exactly(2))
->expects($this->once())
->method('calculateAllParticipantIndividualPrices')
->willReturn([450.0, 500.0]);
@@ -494,4 +542,48 @@ class ParticipantCardAssemblerTest extends TestCase
$this->assertSame('Max Mustermann', $result[0]->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));
}
public function testDummyTokenMatchesOnlyInCreateMode(): void
public function testDummyTokenMatchesInCreateAndEditModes(): void
{
$participant = new ParticipantDto();
$participant->lastName = ParticipantDataPrefiller::TOKEN;
$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