132 lines
4.9 KiB
PHP
132 lines
4.9 KiB
PHP
<?php
|
|
|
|
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;
|
|
|
|
/**
|
|
* Tests for BookingDto validation and business logic.
|
|
*
|
|
* Email uniqueness validation tests have been moved to ParticipantEditDtoTest
|
|
* as part of the refactoring to use the wrapper DTO pattern.
|
|
*/
|
|
class BookingDtoTest extends TestCase
|
|
{
|
|
public function testBookingDtoCanBeInstantiated(): void
|
|
{
|
|
$travel = new Travel();
|
|
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
|
|
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
|
|
|
|
$bookingDto = new BookingDto($travel, 1);
|
|
|
|
$this->assertInstanceOf(BookingDto::class, $bookingDto);
|
|
$this->assertSame($travel, $bookingDto->travel);
|
|
$this->assertSame(BookingDto::MODE_CREATE, $bookingDto->getMode());
|
|
}
|
|
|
|
public function testUnserializeHandlesIntTravelId(): void
|
|
{
|
|
$travel = new Travel();
|
|
$travel->id = 42;
|
|
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
|
|
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
|
|
|
|
$dto = new BookingDto($travel, 1);
|
|
$serialized = serialize($dto);
|
|
$restored = unserialize($serialized);
|
|
|
|
$this->assertInstanceOf(BookingDto::class, $restored);
|
|
$this->assertSame(42, $restored->travel->id);
|
|
}
|
|
|
|
public function testUnserializeHandlesLegacyTravelObject(): void
|
|
{
|
|
$travel = new Travel();
|
|
$travel->id = 42;
|
|
$travel->dateFrom = new \DateTimeImmutable('2025-06-01');
|
|
$travel->dateTo = new \DateTimeImmutable('2025-06-08');
|
|
|
|
// Simulate old session format where 'travel' is a full Travel object
|
|
$data = [
|
|
'travel' => $travel,
|
|
'hotelId' => 1,
|
|
];
|
|
|
|
$dto = new BookingDto(new Travel(), 1);
|
|
$dto->__unserialize($data);
|
|
|
|
$this->assertSame($travel, $dto->travel);
|
|
$this->assertSame(42, $dto->travel->id);
|
|
}
|
|
|
|
public function testUnserializeNormalizesLegacyBodyDimensionsOnParticipants(): 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->height = '149-157';
|
|
$participant->weight = '75';
|
|
$participant->shoeSize = '043';
|
|
|
|
$dto = new BookingDto($travel, 1);
|
|
$dto->participants = [$participant];
|
|
|
|
$restored = unserialize(serialize($dto));
|
|
|
|
$this->assertInstanceOf(BookingDto::class, $restored);
|
|
$this->assertNull($restored->participants[0]->height);
|
|
$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);
|
|
}
|
|
}
|