Files
myep-team/tests/Entity/ApplicationFormSubmissionTest.php
T

124 lines
4.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\ApplicationFormSubmission;
use PHPUnit\Framework\TestCase;
/**
* The payload a submission goes to BusPro as, asserted directly - in the spirit of
* AssignmentTypeTest pinning a form type's choice list. It is the one part of provisioning that
* cannot be rehearsed against the test database at all (the teamer selection is only changeable in
* production), so the keys and the gender mapping are pinned here rather than discovered live.
*/
class ApplicationFormSubmissionTest extends TestCase
{
public function testThePayloadCarriesTheGermanKeysBusProExpects(): void
{
$payload = $this->submission()->toPayload();
$this->assertSame([
'geburtsdatum' => '01.01.1990',
'geschlecht' => 'W',
'vorname' => 'Anna',
'name' => 'Muster',
'anschrift' => [
'strasse' => 'Musterstraße 1',
'plz' => '10115',
'ort' => 'Berlin',
],
'kommunikation' => [
'email' => '[email protected]',
'telefonmobil' => '+49 170 1234567',
'telefonprivat' => '+49 30 1234567',
],
], $payload);
}
/**
* F becomes W, exactly as in Teamer::toPayload(). What BusPro makes of "D" is unverified, so it
* is passed through rather than guessed at - the mapping must not invent a value here.
*/
public function testTheGenderMappingIsTheOneTeamerUses(): void
{
$this->assertSame('W', $this->submission('F')->toPayload()['geschlecht']);
$this->assertSame('M', $this->submission('M')->toPayload()['geschlecht']);
$this->assertSame('D', $this->submission('D')->toPayload()['geschlecht']);
}
/**
* Only a row that predates the contract gets here - street and postcode are required of every
* payload now. The keys still go out empty rather than absent, because BusPro is told what it
* asked for and answers with its own Pflichtfeld error rather than a parse failure.
*/
public function testAnAbsentAddressLeavesTheKeysEmptyRatherThanAbsent(): void
{
$payload = (new ApplicationFormSubmission(
'applicationform',
'Bewerbungsformular',
new \DateTimeImmutable('2026-09-22T12:30:00+02:00'),
'M',
))->toPayload();
$this->assertSame(['strasse' => null, 'plz' => null, 'ort' => null], $payload['anschrift']);
}
public function testTheBirthDateIsParsedStrictly(): void
{
$this->assertSame('1990-01-01', $this->submission()->getDateOfBirth()?->format('Y-m-d'));
// What a row from before the contract looks like: stored, displayed, but not a date.
$this->assertNull($this->submission(birthDate: '01.01.1990')->getDateOfBirth());
$this->assertNull($this->submission(birthDate: 'irgendwann')->getDateOfBirth());
$this->assertNull($this->submission(birthDate: '1990-02-31')->getDateOfBirth());
$this->assertNull($this->submission(birthDate: null)->getDateOfBirth());
}
/**
* The time of day is zeroed rather than "now", or two runs of the same submission would produce
* two different dates of birth.
*/
public function testTheBirthDateHasNoTimeOfDay(): void
{
$this->assertSame('00:00:00', $this->submission()->getDateOfBirth()?->format('H:i:s'));
}
public function testProvisioningStateStartsEmpty(): void
{
$submission = $this->submission();
$this->assertFalse($submission->hasBusProAddress());
$this->assertFalse($submission->isProvisioned());
$submission->setBusProAddressId(141747);
// Both ids or nothing: the selection write needs the person id as well.
$this->assertFalse($submission->hasBusProAddress());
$submission->setBusProPersonId(224526);
$this->assertTrue($submission->hasBusProAddress());
}
private function submission(string $gender = 'F', ?string $birthDate = '1990-01-01'): ApplicationFormSubmission
{
return (new ApplicationFormSubmission(
'applicationform',
'Bewerbungsformular',
new \DateTimeImmutable('2026-09-22T12:30:00+02:00'),
$gender,
))
->setFirstName('Anna')
->setLastName('Muster')
->setEmail('[email protected]')
->setPhone('+49 30 1234567')
->setMobile('+49 170 1234567')
->setBirthDate($birthDate)
->setStreet('Musterstraße 1')
->setZipCode('10115')
->setCity('Berlin')
;
}
}