161 lines
5.0 KiB
PHP
161 lines
5.0 KiB
PHP
<?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);
|
|
}
|
|
}
|