57 lines
1.9 KiB
PHP
57 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Model;
|
|
|
|
use App\Model\ApplicationFormSubmissionDto;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* The normalization the json column relies on: no empty answers, numbers as strings, booleans
|
|
* kept, and a multi-select as a flat list of what was picked.
|
|
*/
|
|
class ApplicationFormSubmissionDtoTest extends TestCase
|
|
{
|
|
public function testEmptyAnswersAreDropped(): void
|
|
{
|
|
$dto = $this->dto(['Nationalität' => 'deutsch', 'Führerschein' => '', 'Sprachen' => [], 'Sport' => null]);
|
|
|
|
$this->assertSame(['Nationalität' => 'deutsch'], $dto->getNormalizedDetails());
|
|
}
|
|
|
|
public function testNumbersBecomeStringsAndBooleansStay(): void
|
|
{
|
|
$dto = $this->dto(['Skifahrer seit' => 2004, 'Datenschutz' => true]);
|
|
|
|
$this->assertSame(['Skifahrer seit' => '2004', 'Datenschutz' => true], $dto->getNormalizedDetails());
|
|
}
|
|
|
|
public function testAMultiSelectStaysAFlatListOfLabels(): void
|
|
{
|
|
$dto = $this->dto(['Ich fahre' => ['Ski', 'Snowboard']]);
|
|
|
|
$this->assertSame(['Ich fahre' => ['Ski', 'Snowboard']], $dto->getNormalizedDetails());
|
|
}
|
|
|
|
public function testARelativeSubmissionTimeIsNotADate(): void
|
|
{
|
|
$this->assertNull((new ApplicationFormSubmissionDto(submittedAt: 'now'))->getSubmittedAt());
|
|
$this->assertNull((new ApplicationFormSubmissionDto(submittedAt: '2026-09-22'))->getSubmittedAt());
|
|
$this->assertNotNull((new ApplicationFormSubmissionDto(submittedAt: '2026-09-22T12:30:00+02:00'))->getSubmittedAt());
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $details
|
|
*/
|
|
private function dto(array $details): ApplicationFormSubmissionDto
|
|
{
|
|
return new ApplicationFormSubmissionDto(
|
|
form: 'applicationform',
|
|
formLabel: 'Bewerbungsformular',
|
|
submittedAt: '2026-09-22T12:30:00+02:00',
|
|
details: $details,
|
|
);
|
|
}
|
|
}
|