116 lines
3.6 KiB
PHP
116 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\BusProNet\Model\Room;
|
|
use App\BusProNet\Model\Travel;
|
|
use App\Form\Model\BookingDto;
|
|
use App\Form\Model\ParticipantDto;
|
|
use App\Service\BookingEditDraftMerger;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Tests that draft restoration never unassigns a room.
|
|
*
|
|
* Edit mode renders the room as static text and never submits assignedRoomId, so a null in
|
|
* the draft payload is always an artefact of a snapshot taken before BusPro reported the
|
|
* assignment - typically for seats added to a group booking shortly before the draft was
|
|
* saved. Replaying such a null would strip the room from the UI and from the outbound
|
|
* zuordnung, so the room id uses the same merge strategy as single-select services.
|
|
*/
|
|
class BookingEditDraftMergerRoomAssignmentTest extends TestCase
|
|
{
|
|
private BookingEditDraftMerger $merger;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->merger = new BookingEditDraftMerger();
|
|
}
|
|
|
|
public function testDraftDoesNotUnassignRoomWhenDraftValueIsNull(): void
|
|
{
|
|
$participant = new ParticipantDto();
|
|
$participant->mutable = true;
|
|
$participant->assignedRoomId = 74;
|
|
|
|
$travel = $this->createTravel([74 => $this->createRoom(74, 'Bett im Mehrbettzimmer')]);
|
|
|
|
$this->apply($travel, $participant, ['assignedRoomId' => null]);
|
|
|
|
$this->assertSame(74, $participant->assignedRoomId);
|
|
}
|
|
|
|
public function testDraftAppliesRoomThatResolvesAgainstTravel(): void
|
|
{
|
|
$participant = new ParticipantDto();
|
|
$participant->mutable = true;
|
|
$participant->assignedRoomId = 74;
|
|
|
|
$travel = $this->createTravel([
|
|
74 => $this->createRoom(74, 'Bett im Mehrbettzimmer'),
|
|
75 => $this->createRoom(75, 'Doppelzimmer'),
|
|
]);
|
|
|
|
$this->apply($travel, $participant, ['assignedRoomId' => 75]);
|
|
|
|
$this->assertSame(75, $participant->assignedRoomId);
|
|
}
|
|
|
|
public function testDraftSkipsRoomThatIsUnknownToTravel(): void
|
|
{
|
|
$participant = new ParticipantDto();
|
|
$participant->mutable = true;
|
|
$participant->assignedRoomId = 74;
|
|
|
|
$travel = $this->createTravel([74 => $this->createRoom(74, 'Bett im Mehrbettzimmer')]);
|
|
|
|
$this->apply($travel, $participant, ['assignedRoomId' => 999]);
|
|
|
|
$this->assertSame(74, $participant->assignedRoomId);
|
|
}
|
|
|
|
public function testDraftClearsRoomRemarks(): void
|
|
{
|
|
$participant = new ParticipantDto();
|
|
$participant->mutable = true;
|
|
$participant->assignedRoomId = 74;
|
|
$participant->remarksRoom = 'Bitte mit Lisa';
|
|
|
|
$travel = $this->createTravel([74 => $this->createRoom(74, 'Bett im Mehrbettzimmer')]);
|
|
|
|
$this->apply($travel, $participant, ['assignedRoomId' => null, 'remarksRoom' => null]);
|
|
|
|
$this->assertNull($participant->remarksRoom);
|
|
$this->assertSame(74, $participant->assignedRoomId);
|
|
}
|
|
|
|
/** @param array<string, mixed> $roomAssignment */
|
|
private function apply(Travel $travel, ParticipantDto $participant, array $roomAssignment): void
|
|
{
|
|
$dto = new BookingDto($travel, 1);
|
|
$dto->participants = [1 => $participant];
|
|
|
|
$this->merger->apply($dto, 1, $participant, ['roomAssignment' => $roomAssignment], $travel);
|
|
}
|
|
|
|
/** @param array<int, Room> $rooms */
|
|
private function createTravel(array $rooms): Travel
|
|
{
|
|
$travel = new Travel();
|
|
$travel->rooms = $rooms;
|
|
|
|
return $travel;
|
|
}
|
|
|
|
private function createRoom(int $id, string $label): Room
|
|
{
|
|
$room = new Room();
|
|
$room->id = $id;
|
|
$room->label = $label;
|
|
|
|
return $room;
|
|
}
|
|
}
|