wip: refactor to cards with individual participant forms
This commit is contained in:
@@ -32,16 +32,37 @@ class ParticipantInsuranceFieldHandlerTest extends TestCase
|
||||
{
|
||||
$dependencies = $this->handler->getDependencies();
|
||||
|
||||
$this->assertEquals(['dateOfBirth'], $dependencies);
|
||||
// Insurance handler depends on all price-affecting fields to ensure accurate reassignment
|
||||
$expectedDependencies = [
|
||||
'dateOfBirth',
|
||||
'skiPass',
|
||||
'rentals',
|
||||
'courses',
|
||||
'additionalServices',
|
||||
'board',
|
||||
'transportationOutbound',
|
||||
'transportationInbound',
|
||||
'pickup',
|
||||
'parking',
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedDependencies, $dependencies);
|
||||
}
|
||||
|
||||
public function testShouldProcessAlwaysReturnsTrue(): void
|
||||
public function testShouldProcessReturnsTrueInCreateMode(): void
|
||||
{
|
||||
$result = $this->handler->shouldProcess([], 0);
|
||||
$result = $this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testShouldProcessReturnsFalseInEditMode(): void
|
||||
{
|
||||
$result = $this->handler->shouldProcess([], BookingDto::MODE_EDIT, 0);
|
||||
|
||||
$this->assertFalse($result, 'Insurance handler should not process in edit mode as API does not return insurance data');
|
||||
}
|
||||
|
||||
public function testProcessFieldSetsInsuranceToNullWhenNoParticipant(): void
|
||||
{
|
||||
$bookingDto = $this->createMockBookingDto();
|
||||
|
||||
@@ -31,8 +31,8 @@ class ParticipantLicensePlateFieldHandlerTest extends TestCase
|
||||
|
||||
public function testShouldProcessAlwaysReturnsTrue(): void
|
||||
{
|
||||
$this->assertTrue($this->handler->shouldProcess([], 0));
|
||||
$this->assertTrue($this->handler->shouldProcess(['some' => 'data'], 5));
|
||||
$this->assertTrue($this->handler->shouldProcess([], BookingDto::MODE_CREATE, 0));
|
||||
$this->assertTrue($this->handler->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
|
||||
}
|
||||
|
||||
public function testProcessFieldWithoutParticipant(): void
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
<?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\BookingPriceCalculatorService;
|
||||
use App\Service\ParticipantCardDataService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantCardDataServiceTest extends TestCase
|
||||
{
|
||||
private ParticipantCardDataService $service;
|
||||
private BookingPriceCalculatorService $priceCalculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->priceCalculator = $this->createMock(BookingPriceCalculatorService::class);
|
||||
$this->service = new ParticipantCardDataService($this->priceCalculator);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithFullParticipantData(): void
|
||||
{
|
||||
// Create test room
|
||||
$room = new Room();
|
||||
$room->id = 1;
|
||||
$room->name = 'Doppelzimmer';
|
||||
$room->price = 100.0;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [$room];
|
||||
|
||||
// Create participant with full data
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = 'Max';
|
||||
$participant->lastName = 'Mustermann';
|
||||
$participant->assignedRoomId = 1;
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
// Mock price calculation
|
||||
$this->priceCalculator
|
||||
->expects($this->once())
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->with($bookingDto)
|
||||
->willReturn([450.50]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('Max Mustermann', $result['name']);
|
||||
$this->assertEquals('Doppelzimmer', $result['roomName']);
|
||||
$this->assertEquals('450,50 €', $result['price']);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithPartialName(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
// Participant with only first name
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = 'Max';
|
||||
$participant->lastName = null;
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('Max', $result['name']);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithNoName(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
// Participant without name
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = null;
|
||||
$participant->lastName = null;
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('Teilnehmer 1', $result['name']);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithEmptyName(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
// Participant with empty strings for names
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = ' ';
|
||||
$participant->lastName = ' ';
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('Teilnehmer 1', $result['name']);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithNoRoomAssignment(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = 'Max';
|
||||
$participant->lastName = 'Mustermann';
|
||||
$participant->assignedRoomId = null;
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('Kein Zimmer zugewiesen', $result['roomName']);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithUnknownRoom(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = 'Max';
|
||||
$participant->lastName = 'Mustermann';
|
||||
$participant->assignedRoomId = 999; // Non-existent room
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('Unbekanntes Zimmer', $result['roomName']);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithZeroPrice(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = 'Max';
|
||||
$participant->lastName = 'Mustermann';
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('0,00 €', $result['price']);
|
||||
}
|
||||
|
||||
public function testGetCardDataWithInvalidIndex(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [];
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Participant at index 0 does not exist');
|
||||
|
||||
$this->service->getCardData($bookingDto, 0);
|
||||
}
|
||||
|
||||
public function testGetAllCardsDataWithMultipleParticipants(): void
|
||||
{
|
||||
// Create test rooms
|
||||
$room1 = new Room();
|
||||
$room1->id = 1;
|
||||
$room1->name = 'Einzelzimmer';
|
||||
|
||||
$room2 = new Room();
|
||||
$room2->id = 2;
|
||||
$room2->name = 'Doppelzimmer';
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [$room1, $room2];
|
||||
|
||||
// Create participants
|
||||
$participant1 = new ParticipantDto();
|
||||
$participant1->firstName = 'Max';
|
||||
$participant1->lastName = 'Mustermann';
|
||||
$participant1->assignedRoomId = 1;
|
||||
|
||||
$participant2 = new ParticipantDto();
|
||||
$participant2->firstName = 'Anna';
|
||||
$participant2->lastName = 'Schmidt';
|
||||
$participant2->assignedRoomId = 2;
|
||||
|
||||
$participant3 = new ParticipantDto();
|
||||
$participant3->firstName = null;
|
||||
$participant3->lastName = null;
|
||||
$participant3->assignedRoomId = 2;
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant1, $participant2, $participant3];
|
||||
|
||||
// Mock price calculation
|
||||
$this->priceCalculator
|
||||
->expects($this->exactly(3))
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->with($bookingDto)
|
||||
->willReturn([450.0, 500.0, 480.0]);
|
||||
|
||||
$result = $this->service->getAllCardsData($bookingDto);
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
|
||||
// First participant
|
||||
$this->assertEquals('Max Mustermann', $result[0]['name']);
|
||||
$this->assertEquals('Einzelzimmer', $result[0]['roomName']);
|
||||
$this->assertEquals('450,00 €', $result[0]['price']);
|
||||
|
||||
// Second participant
|
||||
$this->assertEquals('Anna Schmidt', $result[1]['name']);
|
||||
$this->assertEquals('Doppelzimmer', $result[1]['roomName']);
|
||||
$this->assertEquals('500,00 €', $result[1]['price']);
|
||||
|
||||
// Third participant (no name)
|
||||
$this->assertEquals('Teilnehmer 3', $result[2]['name']);
|
||||
$this->assertEquals('Doppelzimmer', $result[2]['roomName']);
|
||||
$this->assertEquals('480,00 €', $result[2]['price']);
|
||||
}
|
||||
|
||||
public function testGetAllCardsDataWithEmptyParticipants(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [];
|
||||
|
||||
$result = $this->service->getAllCardsData($bookingDto);
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testPriceFormattingWithLargeAmount(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->firstName = 'Max';
|
||||
$participant->lastName = 'Mustermann';
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([1234.56]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertEquals('1.234,56 €', $result['price']);
|
||||
}
|
||||
|
||||
public function testFallbackNameIndexingIsOneBasedNotZeroBased(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
$participant1 = new ParticipantDto();
|
||||
$participant2 = new ParticipantDto();
|
||||
$participant3 = new ParticipantDto();
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant1, $participant2, $participant3];
|
||||
|
||||
$this->priceCalculator
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0, 0.0, 0.0]);
|
||||
|
||||
$result1 = $this->service->getCardData($bookingDto, 0);
|
||||
$result2 = $this->service->getCardData($bookingDto, 1);
|
||||
$result3 = $this->service->getCardData($bookingDto, 2);
|
||||
|
||||
$this->assertEquals('Teilnehmer 1', $result1['name']);
|
||||
$this->assertEquals('Teilnehmer 2', $result2['name']);
|
||||
$this->assertEquals('Teilnehmer 3', $result3['name']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user