fix: ensure drop-offs are submitted when same as pickups
This commit is contained in:
@@ -13,7 +13,7 @@ use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
|||||||
*
|
*
|
||||||
* Drop-off behavior depends on the transportation combination:
|
* Drop-off behavior depends on the transportation combination:
|
||||||
* - BUS+BUS: drop-off is gated behind a "differentDropOff" checkbox.
|
* - BUS+BUS: drop-off is gated behind a "differentDropOff" checkbox.
|
||||||
* When unchecked, BusProNet defaults to the same location as the pickup.
|
* When unchecked, the system assigns the same location as the pickup.
|
||||||
* - PKW+BUS: drop-off is shown directly (no pickup field, no checkbox needed).
|
* - PKW+BUS: drop-off is shown directly (no pickup field, no checkbox needed).
|
||||||
* - BUS+PKW / PKW+PKW: no drop-off applicable, fields are cleared.
|
* - BUS+PKW / PKW+PKW: no drop-off applicable, fields are cleared.
|
||||||
*/
|
*/
|
||||||
@@ -54,14 +54,15 @@ class ParticipantDropOffFieldHandler extends AbstractParticipantFieldHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($hasOutboundBus) {
|
if (true === $hasOutboundBus) {
|
||||||
// BUS+BUS: gated by differentDropOff checkbox
|
// BUS+BUS: gated by differentDropOff checkbox
|
||||||
$checkboxValue = $this->getFieldValue($submittedData, 'differentDropOff');
|
$isChecked = $this->normalizeCheckboxValue($this->getFieldValue($submittedData, 'differentDropOff'));
|
||||||
$isChecked = true === $checkboxValue || '1' === $checkboxValue || 1 === $checkboxValue;
|
|
||||||
|
|
||||||
if (false === $isChecked) {
|
if (false === $isChecked) {
|
||||||
$participant->dropOff = null;
|
|
||||||
$participant->differentDropOff = false;
|
$participant->differentDropOff = false;
|
||||||
|
$participant->dropOff = null !== $participant->pickup
|
||||||
|
? ($bookingDto->travel->dropOffs[$participant->pickup->id] ?? null)
|
||||||
|
: null;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,36 @@ class ParticipantDropOffFieldHandlerTest extends TestCase
|
|||||||
$this->assertTrue($participant->differentDropOff);
|
$this->assertTrue($participant->differentDropOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBusBusCheckboxUncheckedClearsDropOff(): void
|
public function testBusBusCheckboxUncheckedAssignsMatchingDropOff(): void
|
||||||
|
{
|
||||||
|
$dropOff = $this->createDropOff(10, 'Berlin Hbf');
|
||||||
|
$pickup = new Pickup();
|
||||||
|
$pickup->id = 10;
|
||||||
|
$pickup->city = 'Berlin Hbf';
|
||||||
|
|
||||||
|
$bookingDto = $this->createBookingDto(
|
||||||
|
DirectionMapper::SUBTYPE_BUS_API,
|
||||||
|
DirectionMapper::SUBTYPE_BUS_API,
|
||||||
|
[$dropOff]
|
||||||
|
);
|
||||||
|
|
||||||
|
$participant = $bookingDto->getParticipant(0);
|
||||||
|
$participant->pickup = $pickup;
|
||||||
|
$participant->differentDropOff = true;
|
||||||
|
|
||||||
|
$submittedData = [
|
||||||
|
'differentDropOff' => false,
|
||||||
|
'dropOff' => '10',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertNotNull($participant->dropOff);
|
||||||
|
$this->assertSame(10, $participant->dropOff->id);
|
||||||
|
$this->assertFalse($participant->differentDropOff);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBusBusCheckboxUncheckedNoPickupKeepsDropOffNull(): void
|
||||||
{
|
{
|
||||||
$dropOff = $this->createDropOff(10, 'Berlin Hbf');
|
$dropOff = $this->createDropOff(10, 'Berlin Hbf');
|
||||||
$bookingDto = $this->createBookingDto(
|
$bookingDto = $this->createBookingDto(
|
||||||
@@ -84,12 +113,36 @@ class ParticipantDropOffFieldHandlerTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$participant = $bookingDto->getParticipant(0);
|
$participant = $bookingDto->getParticipant(0);
|
||||||
$participant->dropOff = $dropOff;
|
$participant->pickup = null;
|
||||||
$participant->differentDropOff = true;
|
|
||||||
|
$submittedData = [
|
||||||
|
'differentDropOff' => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||||
|
|
||||||
|
$this->assertNull($participant->dropOff);
|
||||||
|
$this->assertFalse($participant->differentDropOff);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBusBusCheckboxUncheckedPickupWithNoMatchingDropOff(): void
|
||||||
|
{
|
||||||
|
$dropOff = $this->createDropOff(10, 'Berlin Hbf');
|
||||||
|
$pickup = new Pickup();
|
||||||
|
$pickup->id = 99;
|
||||||
|
$pickup->city = 'Unknown';
|
||||||
|
|
||||||
|
$bookingDto = $this->createBookingDto(
|
||||||
|
DirectionMapper::SUBTYPE_BUS_API,
|
||||||
|
DirectionMapper::SUBTYPE_BUS_API,
|
||||||
|
[$dropOff]
|
||||||
|
);
|
||||||
|
|
||||||
|
$participant = $bookingDto->getParticipant(0);
|
||||||
|
$participant->pickup = $pickup;
|
||||||
|
|
||||||
$submittedData = [
|
$submittedData = [
|
||||||
'differentDropOff' => false,
|
'differentDropOff' => false,
|
||||||
'dropOff' => '10',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user