feat: move scope of enforced 'option' status to full booking

addresses #869chtfeq
This commit is contained in:
Björn Fromme
2026-03-19 16:15:07 +01:00
parent 45d05786da
commit df8566e1b5
19 changed files with 388 additions and 329 deletions
@@ -5,7 +5,9 @@ declare(strict_types=1);
namespace App\Tests\BusProNet\Service\StatusRule;
use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel;
use App\BusProNet\Service\StatusRule\ChaperonServiceStatusRule;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use PHPUnit\Framework\TestCase;
@@ -20,99 +22,99 @@ class ChaperonServiceStatusRuleTest extends TestCase
public function testReturnsTrueWhenBegleitpersonInAdditionalServices(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skibegleitperson Kurs';
$participant->additionalServices = [$service];
$bookingDto->participants[0]->additionalServices = [$service];
$this->assertTrue($this->rule->evaluate($participant));
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInCourses(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Begleitperson Anfängerkurs';
$participant->courses = [$service];
$service->label = 'Begleitperson Anfaengerkurs';
$bookingDto->participants[0]->courses = [$service];
$this->assertTrue($this->rule->evaluate($participant));
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInBoard(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Halbpension Begleitperson';
$participant->board = [$service];
$bookingDto->participants[0]->board = [$service];
$this->assertTrue($this->rule->evaluate($participant));
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInRentals(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skiset Begleitperson';
$participant->rentals = [$service];
$bookingDto->participants[0]->rentals = [$service];
$this->assertTrue($this->rule->evaluate($participant));
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInSkiPass(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skipass Begleitperson 6 Tage';
$participant->skiPass = $service;
$bookingDto->participants[0]->skiPass = $service;
$this->assertTrue($this->rule->evaluate($participant));
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenBegleitpersonInVeg(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Vegetarisch Begleitperson';
$participant->veg = $service;
$bookingDto->participants[0]->veg = $service;
$this->assertTrue($this->rule->evaluate($participant));
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsTrueWhenSecondParticipantMatches(): void
{
$bookingDto = $this->createBookingDtoWithParticipantCount(2);
$service = new Service();
$service->label = 'Begleitperson Service';
$bookingDto->participants[1]->additionalServices = [$service];
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsFalseWhenNoBegleitpersonService(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'Skipass 6 Tage Erwachsene';
$participant->skiPass = $service;
$bookingDto->participants[0]->skiPass = $service;
$this->assertFalse($this->rule->evaluate($participant));
$this->assertFalse($this->rule->evaluate($bookingDto));
}
public function testReturnsFalseWithEmptyServices(): void
public function testReturnsFalseWithEmptyParticipants(): void
{
$participant = new ParticipantDto();
$bookingDto = new BookingDto($this->createTravel(), 1);
$this->assertFalse($this->rule->evaluate($participant));
$this->assertFalse($this->rule->evaluate($bookingDto));
}
public function testCaseInsensitiveMatch(): void
{
$participant = new ParticipantDto();
$bookingDto = $this->createBookingDtoWithParticipant();
$service = new Service();
$service->label = 'BEGLEITPERSON Kurs';
$participant->additionalServices = [$service];
$bookingDto->participants[0]->additionalServices = [$service];
$this->assertTrue($this->rule->evaluate($participant));
}
public function testMixedCaseMatch(): void
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = 'beGleitPerson Kurs';
$participant->courses = [$service];
$this->assertTrue($this->rule->evaluate($participant));
$this->assertTrue($this->rule->evaluate($bookingDto));
}
public function testReturnsStatusO(): void
@@ -133,28 +135,32 @@ class ChaperonServiceStatusRuleTest extends TestCase
$this->assertNotEmpty($description);
}
public function testHandlesNullLabel(): void
private function createBookingDtoWithParticipant(): BookingDto
{
$participant = new ParticipantDto();
$service = new Service();
$service->label = null;
$participant->additionalServices = [$service];
$this->assertFalse($this->rule->evaluate($participant));
return $this->createBookingDtoWithParticipantCount(1);
}
public function testMultipleServicesWithOneBegleitperson(): void
private function createBookingDtoWithParticipantCount(int $count): BookingDto
{
$participant = new ParticipantDto();
$bookingDto = new BookingDto($this->createTravel(), 1);
$normalService = new Service();
$normalService->label = 'Skipass 6 Tage';
for ($i = 0; $i < $count; ++$i) {
$participant = new ParticipantDto();
$participant->index = $i;
$bookingDto->participants[$i] = $participant;
}
$begleitpersonService = new Service();
$begleitpersonService->label = 'Skipass Begleitperson';
return $bookingDto;
}
$participant->additionalServices = [$normalService, $begleitpersonService];
private function createTravel(): Travel
{
$travel = new Travel();
$travel->id = 1;
$travel->hotelId = 1;
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
$this->assertTrue($this->rule->evaluate($participant));
return $travel;
}
}