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; } }