Files
myep/tests/Form/Service/EditFieldStateProviderTest.php

82 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Form\Service;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\AgencyLoader;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Service\EditFieldStateProvider;
use PHPUnit\Framework\TestCase;
/**
* Covers the edit-flow email requirement, which follows the same age rule as the create flow
* but stands down entirely for internal agency bookings, where staff leave personal data blank.
*/
class EditFieldStateProviderTest extends TestCase
{
private EditFieldStateProvider $provider;
protected function setUp(): void
{
$this->provider = new EditFieldStateProvider();
}
public function testEmailIsRequiredForNonApplicantAdult(): void
{
$bookingDto = $this->createBookingDto(new \DateTimeImmutable('1990-01-01'), false);
$this->assertTrue($this->provider->getFieldState('email', $bookingDto, 1)['required']);
}
public function testEmailIsNotRequiredForNonApplicantChild(): void
{
$bookingDto = $this->createBookingDto(new \DateTimeImmutable('2015-01-01'), false);
$this->assertFalse($this->provider->getFieldState('email', $bookingDto, 1)['required']);
}
public function testEmailIsNotRequiredForInternalAgencyBookingsEvenForAdults(): void
{
$bookingDto = $this->createBookingDto(new \DateTimeImmutable('1990-01-01'), true);
$this->assertFalse(
$this->provider->getFieldState('email', $bookingDto, 1)['required'],
'Internal agency bookings leave personal data optional throughout'
);
}
public function testEmailIsRequiredForTheApplicantOutsideInternalAgencyBookings(): void
{
$bookingDto = $this->createBookingDto(new \DateTimeImmutable('1990-01-01'), false);
$this->assertTrue($this->provider->getFieldState('email', $bookingDto, 0)['required']);
}
private function createBookingDto(\DateTimeImmutable $dependentDateOfBirth, bool $internalAgency): BookingDto
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('+30 days');
$travel->dateTo = new \DateTimeImmutable('+37 days');
$applicant = new ParticipantDto();
$applicant->index = 0;
$applicant->dateOfBirth = new \DateTimeImmutable('1980-01-01');
$dependent = new ParticipantDto();
$dependent->index = 1;
$dependent->dateOfBirth = $dependentDateOfBirth;
$bookingDto = new BookingDto($travel, 1);
$bookingDto->participants = [$applicant, $dependent];
if (true === $internalAgency) {
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
}
return $bookingDto;
}
}