feat: disable body dimensions validation for selection id 1475
closes #869dne7qt
This commit is contained in:
@@ -4,18 +4,27 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Validator\Constraints;
|
||||
|
||||
use App\BusProNet\Model\CrmSelection;
|
||||
use App\BusProNet\Model\CrmSelectionGroup;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Model\ParticipantEditDto;
|
||||
use App\Validator\Constraints\Participant;
|
||||
use App\Validator\Constraints\ParticipantValidator;
|
||||
use App\Validator\SelectionBasedBodyDimensionExemption;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
protected function createValidator(): ParticipantValidator
|
||||
{
|
||||
return new ParticipantValidator();
|
||||
return new ParticipantValidator(
|
||||
bodyDimensionRanges: [],
|
||||
bodyDimensionExemption: new SelectionBasedBodyDimensionExemption()
|
||||
);
|
||||
}
|
||||
|
||||
public function testParticipantWithRentalsAndBodyMeasurementsPassesValidation(): void
|
||||
@@ -111,6 +120,46 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testParticipantWithOutOfRangeBodyDimensionsFailsValidationWithoutSelection1474(): void
|
||||
{
|
||||
$wrapper = $this->createWrapperWithParticipantAndTravelSelections(
|
||||
$this->createValidParticipantWithOutOfRangeBodyDimensions(),
|
||||
[2001]
|
||||
);
|
||||
|
||||
$this->setRoot($wrapper);
|
||||
$this->validator->validate($wrapper->participant, new Participant());
|
||||
|
||||
$this->assertCount(3, $this->context->getViolations());
|
||||
}
|
||||
|
||||
public function testParticipantWithOutOfRangeBodyDimensionsPassesValidationInCreateModeWithSelection1474(): void
|
||||
{
|
||||
$wrapper = $this->createWrapperWithParticipantAndTravelSelections(
|
||||
$this->createValidParticipantWithOutOfRangeBodyDimensions(),
|
||||
[1474]
|
||||
);
|
||||
|
||||
$this->setRoot($wrapper);
|
||||
$this->validator->validate($wrapper->participant, new Participant());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testParticipantWithOutOfRangeBodyDimensionsPassesValidationInEditModeWithSelection1474(): void
|
||||
{
|
||||
$wrapper = $this->createWrapperWithParticipantAndTravelSelections(
|
||||
$this->createValidParticipantWithOutOfRangeBodyDimensions(),
|
||||
[1474],
|
||||
true
|
||||
);
|
||||
|
||||
$this->setRoot($wrapper);
|
||||
$this->validator->validate($wrapper->participant, new Participant());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testCanceledParticipantSkipsValidation(): void
|
||||
{
|
||||
$participant = $this->createValidParticipant();
|
||||
@@ -226,4 +275,61 @@ class ParticipantValidatorTest extends ConstraintValidatorTestCase
|
||||
|
||||
return $pickup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $selectionIds
|
||||
*/
|
||||
private function createWrapperWithParticipantAndTravelSelections(
|
||||
ParticipantDto $participant,
|
||||
array $selectionIds,
|
||||
bool $editMode = false,
|
||||
): ParticipantEditDto {
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
|
||||
$travel->selectionGroups = [
|
||||
1 => $this->createSelectionGroup(1, $selectionIds),
|
||||
];
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
if (true === $editMode) {
|
||||
$bookingDto->booking = new \App\BusProNet\Model\Booking();
|
||||
}
|
||||
|
||||
return new ParticipantEditDto(
|
||||
participant: $participant,
|
||||
bookingContext: $bookingDto,
|
||||
);
|
||||
}
|
||||
|
||||
private function createValidParticipantWithOutOfRangeBodyDimensions(): ParticipantDto
|
||||
{
|
||||
$participant = $this->createValidParticipant();
|
||||
$participant->rentals = [$this->createMockService()];
|
||||
$participant->height = '999';
|
||||
$participant->weight = '999';
|
||||
$participant->shoeSize = '999';
|
||||
|
||||
return $participant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $selectionIds
|
||||
*/
|
||||
private function createSelectionGroup(int $groupId, array $selectionIds): CrmSelectionGroup
|
||||
{
|
||||
$group = new CrmSelectionGroup();
|
||||
$group->id = $groupId;
|
||||
$group->selections = [];
|
||||
|
||||
foreach ($selectionIds as $selectionId) {
|
||||
$selection = new CrmSelection();
|
||||
$selection->id = $selectionId;
|
||||
$group->selections[] = $selection;
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user