fix: applicant split in edit mode, drop create-mode agency checks

This commit is contained in:
fromme committed 2026-10-16 17:49:04 +02:00
1 parent ad6e42ab0c
commit 38f0f23ea3
12 files changed
+167 -68

No files matched your search

+50 -3
View File
@@ -148,14 +148,25 @@ class BookingDtoTest extends TestCase
$this->assertFalse($dto->isFirstParticipantApplicant());
}
public function testInternalAgencyBookingNeverHasTheFirstParticipantAsApplicant(): void
public function testInternalAgencyBookingNeverHasTheFirstParticipantAsApplicantInEditMode(): void
{
$dto = $this->createCreateModeDto();
$dto = $this->createEditModeDto(100, 100);
$dto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
$this->assertFalse(
$dto->isFirstParticipantApplicant(),
'Their applicant is a staff member who never travels'
'Their applicant is a customer who is not the first traveller, whatever the ids say'
);
}
public function testAgencyCodeDoesNotDecideAnythingInCreateMode(): void
{
$dto = $this->createCreateModeDto();
$dto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
$this->assertTrue(
$dto->isFirstParticipantApplicant(),
'Internal agency bookings are never created here, so the code is only passed on'
);
}
@@ -358,6 +369,42 @@ class BookingDtoTest extends TestCase
$this->assertContains('Die anmeldende Person muss volljährig sein.', $messages);
}
public function testEditModeDoesNotAskASplitBookingsFirstParticipantForAnAddress(): void
{
$dto = $this->createEditModeDto(100, 200);
$dto->participants[0]->index = 0;
$dto->participants[0]->address = null;
$this->assertSame([], $this->collectFirstParticipantAddressPaths($dto));
}
public function testEditModeStillAsksTheApplicantForAnAddress(): void
{
$dto = $this->createEditModeDto(100, 100);
$dto->participants[0]->index = 0;
$dto->participants[0]->address = null;
$this->assertSame(['participants[0].address'], $this->collectFirstParticipantAddressPaths($dto));
}
/**
* @return list<string>
*/
private function collectFirstParticipantAddressPaths(BookingDto $dto): array
{
$validator = Validation::createValidatorBuilder()->enableAttributeMapping()->getValidator();
$violations = $validator->validate($dto, null, ['booking_edit', 'strict_required']);
$paths = [];
foreach ($violations as $violation) {
if (str_starts_with($violation->getPropertyPath(), 'participants[0].address')) {
$paths[] = $violation->getPropertyPath();
}
}
return $paths;
}
private function createAddress(): Address
{
$address = new Address();
+33 -1
View File
@@ -8,6 +8,7 @@ use App\BusProNet\Constants;
use App\BusProNet\Model\Address;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Insurance;
use App\BusProNet\Model\PersonalData;
use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\AgencyLoader;
@@ -703,7 +704,6 @@ class ParticipantEditDtoTest extends TestCase
$bookingDto = new BookingDto($travel, 1);
$bookingDto->booking = new Booking();
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
$participant0 = $this->createAdultParticipant('[email protected]');
$participant0->index = 0;
@@ -740,6 +740,38 @@ class ParticipantEditDtoTest extends TestCase
$this->assertCount(0, $addressViolations1, 'Non-applicant address should not be required in edit submission');
}
public function testEditSubmissionDoesNotAskASplitBookingsFirstParticipantForAnAddress(): void
{
$travel = $this->createTravelOfferingSkiPasses();
$applicant = new PersonalData();
$applicant->personId = 100;
$bookingDto = new BookingDto($travel, 1);
$bookingDto->booking = new Booking();
$bookingDto->booking->applicant = $applicant;
$participant0 = $this->createAdultParticipant('[email protected]');
$participant0->index = 0;
$participant0->personId = 200;
$participant0->address = null;
$bookingDto->participants = [$participant0];
$wrapper0 = new ParticipantEditDto(
participant: $bookingDto->participants[0],
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()
);
$this->assertCount(0, $addressViolations0, 'A traveller who is not the applicant owes no address');
}
public function testSkiPassAgeCalculatedAtTravelDate(): void
{
$travel = $this->createTravelOfferingSkiPasses();
@@ -4,7 +4,9 @@ declare(strict_types=1);
namespace App\Tests\Form\Service;
use App\BusProNet\Model\Booking;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\AgencyLoader;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Service\ParticipantDateOfBirthFieldHandler;
@@ -79,6 +81,30 @@ class ParticipantEmailFieldHandlerTest extends TestCase
$this->assertSame('[email protected]', $bookingDto->participants[0]->email);
}
public function testEditModeNeverPreFills(): void
{
$bookingDto = $this->createBookingDto();
$bookingDto->booking = new Booking();
$this->handler->processField(['email' => ''], $bookingDto, 1);
$this->assertNull(
$bookingDto->participants[1]->email,
'participant[0] is not reliably the applicant in edit mode, and a blank may be intended'
);
}
public function testEditModeLeavesAnInternalAgencyChildWithoutEmail(): void
{
$bookingDto = $this->createBookingDto();
$bookingDto->booking = new Booking();
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
$this->handler->processField(['email' => ''], $bookingDto, 1);
$this->assertNull($bookingDto->participants[1]->email);
}
public function testHandlerRunsAfterDateOfBirth(): void
{
$this->assertSame(