fix: incorrect rules around family insurances
addresses #869dr80qj
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Service\Condition;
|
||||
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\Condition\FamilyInsuranceActiveCondition;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FamilyInsuranceActiveConditionTest extends TestCase
|
||||
{
|
||||
private FamilyInsuranceActiveCondition $condition;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->condition = new FamilyInsuranceActiveCondition();
|
||||
}
|
||||
|
||||
public function testAlwaysFalseForApplicant(): void
|
||||
{
|
||||
$applicant = new ParticipantDto();
|
||||
$applicant->index = 0;
|
||||
$applicant->insurance = $this->createFamilyInsurance();
|
||||
|
||||
$bookingDto = new BookingDto(new Travel(), 1);
|
||||
$bookingDto->participants = [$applicant];
|
||||
|
||||
$result = $this->condition->evaluate($bookingDto, 0, []);
|
||||
|
||||
$this->assertFalse($result, 'Applicant is never affected by their own family insurance selection');
|
||||
}
|
||||
|
||||
public function testTrueForDependentWhenApplicantHasFamilyInsurance(): void
|
||||
{
|
||||
$applicant = new ParticipantDto();
|
||||
$applicant->index = 0;
|
||||
$applicant->insurance = $this->createFamilyInsurance();
|
||||
|
||||
$dependent = new ParticipantDto();
|
||||
$dependent->index = 1;
|
||||
|
||||
$bookingDto = new BookingDto(new Travel(), 1);
|
||||
$bookingDto->participants = [$applicant, $dependent];
|
||||
|
||||
$result = $this->condition->evaluate($bookingDto, 1, []);
|
||||
|
||||
$this->assertTrue($result, 'Dependent insurance field must be hidden when applicant has family insurance');
|
||||
}
|
||||
|
||||
public function testFalseForDependentWhenApplicantHasNonFamilyInsurance(): void
|
||||
{
|
||||
$nonFamilyInsurance = new Insurance();
|
||||
$nonFamilyInsurance->familyInsurance = false;
|
||||
|
||||
$applicant = new ParticipantDto();
|
||||
$applicant->index = 0;
|
||||
$applicant->insurance = $nonFamilyInsurance;
|
||||
|
||||
$dependent = new ParticipantDto();
|
||||
$dependent->index = 1;
|
||||
|
||||
$bookingDto = new BookingDto(new Travel(), 1);
|
||||
$bookingDto->participants = [$applicant, $dependent];
|
||||
|
||||
$result = $this->condition->evaluate($bookingDto, 1, []);
|
||||
|
||||
$this->assertFalse($result, 'Dependent should keep their own insurance choice for non-family insurance');
|
||||
}
|
||||
|
||||
public function testFalseForDependentWhenApplicantHasNoInsurance(): void
|
||||
{
|
||||
$applicant = new ParticipantDto();
|
||||
$applicant->index = 0;
|
||||
|
||||
$dependent = new ParticipantDto();
|
||||
$dependent->index = 1;
|
||||
|
||||
$bookingDto = new BookingDto(new Travel(), 1);
|
||||
$bookingDto->participants = [$applicant, $dependent];
|
||||
|
||||
$result = $this->condition->evaluate($bookingDto, 1, []);
|
||||
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testGetDependentFieldsReturnsInsurance(): void
|
||||
{
|
||||
$result = $this->condition->getDependentFields();
|
||||
|
||||
$this->assertSame(['insurance'], $result);
|
||||
}
|
||||
|
||||
public function testGetDescriptionReturnsString(): void
|
||||
{
|
||||
$result = $this->condition->getDescription();
|
||||
|
||||
$this->assertIsString($result);
|
||||
$this->assertStringContainsString('family insurance', $result);
|
||||
}
|
||||
|
||||
private function createFamilyInsurance(): Insurance
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->familyInsurance = true;
|
||||
|
||||
return $insurance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user