feat: auto-booking services
addresses #869cfcptv
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Service;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\ParticipantAdditionalServicesFieldHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantAdditionalServicesFieldHandlerTest extends TestCase
|
||||
{
|
||||
public function testDeselectAutoBookServiceAddsOptOutId(): void
|
||||
{
|
||||
$autoBookService = new Service();
|
||||
$autoBookService->id = 10;
|
||||
$autoBookService->subType = Constants::TOKEN_ADDITIONAL;
|
||||
$autoBookService->label = 'Auto Book';
|
||||
$autoBookService->autoBook = true;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||
$travel->additionalServices = [10 => $autoBookService];
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$participant->additionalServices = [$autoBookService];
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
$handler = new ParticipantAdditionalServicesFieldHandler();
|
||||
$handler->processField([], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([10], $participant->autoBookOptOutServiceIds);
|
||||
$this->assertSame([], $participant->additionalServices);
|
||||
}
|
||||
|
||||
public function testDeselectMandatoryAutoBookServiceDoesNotAddOptOutId(): void
|
||||
{
|
||||
$service = new Service();
|
||||
$service->id = 11;
|
||||
$service->subType = Constants::TOKEN_ADDITIONAL;
|
||||
$service->label = 'Mandatory Auto Book';
|
||||
$service->mandatory = true;
|
||||
$service->autoBook = true;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||
$travel->additionalServices = [11 => $service];
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$participant->additionalServices = [$service];
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
$handler = new ParticipantAdditionalServicesFieldHandler();
|
||||
$handler->processField([], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([], $participant->autoBookOptOutServiceIds);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user