feat: move prepopulation guards into participant service
This commit is contained in:
@@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Service;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\DummyDataFillService;
|
||||
use Carbon\CarbonImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DummyDataFillServiceTest extends TestCase
|
||||
{
|
||||
private DummyDataFillService $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->service = new DummyDataFillService();
|
||||
}
|
||||
|
||||
public function testTokenMatchInCreateMode(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->lastName = DummyDataFillService::TOKEN;
|
||||
|
||||
$this->assertTrue($this->service->isTokenMatch($participant, BookingDto::MODE_CREATE));
|
||||
}
|
||||
|
||||
public function testTokenMatchReturnsFalseInEditMode(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->lastName = DummyDataFillService::TOKEN;
|
||||
|
||||
$this->assertFalse($this->service->isTokenMatch($participant, BookingDto::MODE_EDIT));
|
||||
}
|
||||
|
||||
public function testNonMatchingLastNameReturnsFalse(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->lastName = 'Schmidt';
|
||||
|
||||
$this->assertFalse($this->service->isTokenMatch($participant, BookingDto::MODE_CREATE));
|
||||
}
|
||||
|
||||
public function testNullLastNameReturnsFalse(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->lastName = null;
|
||||
|
||||
$this->assertFalse($this->service->isTokenMatch($participant, BookingDto::MODE_CREATE));
|
||||
}
|
||||
|
||||
public function testFillSetsFirstNameWithParticipantNumber(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant, 0);
|
||||
|
||||
$this->assertSame('Vorname 1', $participant->firstName);
|
||||
}
|
||||
|
||||
public function testFillSetsLastNameWithParticipantNumberAndTime(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 15, 14, 30));
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant, 0);
|
||||
|
||||
$this->assertSame('Muster 1 14:30', $participant->lastName);
|
||||
|
||||
CarbonImmutable::setTestNow();
|
||||
}
|
||||
|
||||
public function testFillSetsMobilePhone(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant, 0);
|
||||
|
||||
$this->assertSame('0171/111111', $participant->mobile);
|
||||
}
|
||||
|
||||
public function testFillSetsEmailWithParticipantNumber(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant, 0);
|
||||
|
||||
$this->assertSame('[email protected]', $participant->email);
|
||||
}
|
||||
|
||||
public function testFillUsesOneBasedParticipantNumber(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 15, 9, 5));
|
||||
|
||||
$participant0 = new ParticipantDto();
|
||||
$participant1 = new ParticipantDto();
|
||||
$participant4 = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant0, 0);
|
||||
$this->service->fill($participant1, 1);
|
||||
$this->service->fill($participant4, 4);
|
||||
|
||||
$this->assertSame('Vorname 1', $participant0->firstName);
|
||||
$this->assertSame('Muster 1 09:05', $participant0->lastName);
|
||||
$this->assertSame('[email protected]', $participant0->email);
|
||||
|
||||
$this->assertSame('Vorname 2', $participant1->firstName);
|
||||
$this->assertSame('Muster 2 09:05', $participant1->lastName);
|
||||
$this->assertSame('[email protected]', $participant1->email);
|
||||
|
||||
$this->assertSame('Vorname 5', $participant4->firstName);
|
||||
$this->assertSame('Muster 5 09:05', $participant4->lastName);
|
||||
$this->assertSame('[email protected]', $participant4->email);
|
||||
|
||||
CarbonImmutable::setTestNow();
|
||||
}
|
||||
|
||||
public function testFillSetsDateOfBirthToTwentyYearsAgo(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 3, 10, 12, 0));
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant, 0);
|
||||
|
||||
$this->assertInstanceOf(\DateTimeImmutable::class, $participant->dateOfBirth);
|
||||
$this->assertSame('2006-03-10', $participant->dateOfBirth->format('Y-m-d'));
|
||||
|
||||
CarbonImmutable::setTestNow();
|
||||
}
|
||||
|
||||
public function testFillSetsAddress(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant, 0);
|
||||
|
||||
$this->assertNotNull($participant->address);
|
||||
$this->assertSame('Musterstr. 123', $participant->address->street);
|
||||
$this->assertSame('99999', $participant->address->postCode);
|
||||
$this->assertSame('MusterOrt', $participant->address->city);
|
||||
$this->assertSame('Deutschland', $participant->address->country);
|
||||
}
|
||||
|
||||
public function testFillSetsAddressForAllParticipants(): void
|
||||
{
|
||||
$participant0 = new ParticipantDto();
|
||||
$participant3 = new ParticipantDto();
|
||||
|
||||
$this->service->fill($participant0, 0);
|
||||
$this->service->fill($participant3, 3);
|
||||
|
||||
$this->assertNotNull($participant0->address);
|
||||
$this->assertNotNull($participant3->address);
|
||||
$this->assertSame('Musterstr. 123', $participant3->address->street);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Model\RoomSelectionDto;
|
||||
use App\Service\BookingParticipantCountService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
class BookingParticipantCountServiceTest extends TestCase
|
||||
{
|
||||
@@ -44,31 +43,6 @@ class BookingParticipantCountServiceTest extends TestCase
|
||||
$this->assertSame(7, $bookingDto->participants[7]->index);
|
||||
}
|
||||
|
||||
public function testEnsureCorrectNumberOfParticipantsPrepopulatesFreshApplicant(): void
|
||||
{
|
||||
$travel = $this->createTravel([1 => 2]);
|
||||
$bookingDto = new BookingDto($travel, 123);
|
||||
$bookingDto->roomSelections = [$this->createRoomSelection(1, 1)];
|
||||
$bookingDto->participants = [new ParticipantDto()];
|
||||
|
||||
$user = $this->createMock(UserInterface::class);
|
||||
$callbackCalled = false;
|
||||
|
||||
$this->service->ensureCorrectNumberOfParticipants(
|
||||
$bookingDto,
|
||||
$user,
|
||||
function (UserInterface $userArg, ParticipantDto $participant) use (&$callbackCalled): ParticipantDto {
|
||||
$callbackCalled = true;
|
||||
$participant->firstName = 'Alex';
|
||||
|
||||
return $participant;
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertTrue($callbackCalled);
|
||||
$this->assertSame('Alex', $bookingDto->participants[0]->firstName);
|
||||
}
|
||||
|
||||
private function createTravel(array $roomCapacities): Travel
|
||||
{
|
||||
$travel = new Travel();
|
||||
|
||||
@@ -10,9 +10,11 @@ use App\BusProNet\Model\Communication;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Entity\User;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Security\Crypt;
|
||||
use App\Service\ParticipantPrepopulationService;
|
||||
use Carbon\CarbonImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
@@ -240,6 +242,44 @@ class ParticipantPrepopulationServiceTest extends TestCase
|
||||
$this->assertTrue($result->bulkInsuranceBooking);
|
||||
}
|
||||
|
||||
public function testShouldPrepopulateApplicantOnlyWhenFresh(): void
|
||||
{
|
||||
$fresh = new ParticipantDto();
|
||||
$fresh->firstName = '';
|
||||
|
||||
$filled = new ParticipantDto();
|
||||
$filled->firstName = 'Already set';
|
||||
|
||||
$this->assertTrue($this->service->shouldPrepopulateApplicant($fresh));
|
||||
$this->assertFalse($this->service->shouldPrepopulateApplicant($filled));
|
||||
}
|
||||
|
||||
public function testDummyTokenMatchesOnlyInCreateMode(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->lastName = ParticipantPrepopulationService::TOKEN;
|
||||
|
||||
$this->assertTrue($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_CREATE));
|
||||
$this->assertFalse($this->service->isDummyDataFillRequested($participant, BookingDto::MODE_EDIT));
|
||||
}
|
||||
|
||||
public function testFillDummyParticipantSetsGeneratedData(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 1, 15, 14, 30));
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$this->service->fillDummyParticipant($participant, 0);
|
||||
|
||||
$this->assertSame('Vorname 1', $participant->firstName);
|
||||
$this->assertSame('Muster 1 14:30', $participant->lastName);
|
||||
$this->assertSame('0171/111111', $participant->mobile);
|
||||
$this->assertSame('[email protected]', $participant->email);
|
||||
$this->assertSame('2006-01-15', $participant->dateOfBirth?->format('Y-m-d'));
|
||||
$this->assertSame('Musterstr. 123', $participant->address?->street);
|
||||
|
||||
CarbonImmutable::setTestNow();
|
||||
}
|
||||
|
||||
private function createUser(string $email, string $encryptedPassword): User
|
||||
{
|
||||
$user = new User($email);
|
||||
|
||||
Reference in New Issue
Block a user