feat: financial data check for teamers, improved enforced checks logic

addresses #869at5rtp
This commit is contained in:
Björn Fromme
2026-08-10 18:06:25 +02:00
parent fd5d478a5c
commit 388ecf9603
22 changed files with 1196 additions and 195 deletions
+166
View File
@@ -0,0 +1,166 @@
<?php
declare(strict_types=1);
namespace App\Tests\Form;
use App\Entity\Embeddable\BankAccount;
use App\Entity\Teamer;
use App\Entity\User;
use App\Form\FinancialDataType;
use App\Model\FinancialDataDto;
use App\RequiredTeamerCheck\FinancialDataRequiredCheck;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
class FinancialDataTypeTest extends KernelTestCase
{
/**
* The whole point of the dedicated check page: a teamer who is missing photo,
* language, health insurance and address fails the entity's 'profile' group,
* but must still be able to save the five fields that open the gate. The DTO
* carries its constraints in the default group, so nothing from the entity
* bleeds in.
*/
public function testSubmitSucceedsForATeamerWhoFailsTheProfileGroup(): void
{
$teamer = new Teamer();
$formData = FinancialDataDto::fromTeamer($teamer);
$form = $this->createForm($formData);
$form->submit($this->validSubmission());
$this->assertTrue($form->isValid());
$formData->applyTo($teamer);
$this->assertNull($teamer->getPhoto());
$this->assertNull($teamer->getLanguage());
$this->assertNull($teamer->getHealthInsuranceCompany());
}
/**
* Guards against the form and the check drifting apart: what the form accepts
* as complete must be exactly what unlocks the portal.
*/
public function testAValidSubmissionSatisfiesTheCheck(): void
{
$teamer = new Teamer();
$user = (new User())
->setRoles(['ROLE_TEAMER'])
->setTeamer($teamer)
;
$check = new FinancialDataRequiredCheck();
$this->assertFalse($check->isSatisfied($user));
$formData = FinancialDataDto::fromTeamer($teamer);
$form = $this->createForm($formData);
$form->submit($this->validSubmission());
$formData->applyTo($teamer);
$this->assertTrue($check->isSatisfied($user));
}
public function testEmptySubmitIsRejectedOnEveryField(): void
{
$form = $this->createForm(new FinancialDataDto());
$form->submit([
'taxId' => '',
'iban' => '',
'bic' => '',
'bank' => '',
'holder' => '',
]);
$this->assertFalse($form->isValid());
foreach (['taxId', 'iban', 'bic', 'bank', 'holder'] as $field) {
$this->assertCount(1, $form->get($field)->getErrors(), sprintf('Expected one error on "%s"', $field));
}
}
public function testMalformedIbanIsRejected(): void
{
$form = $this->createForm(new FinancialDataDto());
$form->submit(array_merge($this->validSubmission(), ['iban' => 'DE00 not an iban']));
$this->assertFalse($form->isValid());
$this->assertCount(1, $form->get('iban')->getErrors());
$this->assertCount(0, $form->get('taxId')->getErrors());
}
public function testFromTeamerToleratesAMissingBankAccount(): void
{
$teamer = (new Teamer())->setTaxId('12345678901');
$formData = FinancialDataDto::fromTeamer($teamer);
$this->assertSame('12345678901', $formData->getTaxId());
$this->assertNull($formData->getIban());
}
public function testApplyToCreatesABankAccountWhenTheTeamerHasNone(): void
{
$teamer = new Teamer();
$this->assertNull($teamer->getBankAccount());
(new FinancialDataDto())
->setTaxId('12345678901')
->setIban('DE02120300000000202051')
->setBic('BYLADEM1001')
->setBank('Deutsche Kreditbank')
->setHolder('Erika Mustermann')
->applyTo($teamer)
;
$this->assertInstanceOf(BankAccount::class, $teamer->getBankAccount());
$this->assertSame('DE02120300000000202051', $teamer->getBankAccount()->getIban());
$this->assertSame('12345678901', $teamer->getTaxId());
}
public function testFromTeamerRoundTripsAnExistingBankAccount(): void
{
$teamer = (new Teamer())
->setTaxId('12345678901')
->setBankAccount(
(new BankAccount())
->setIban('DE02120300000000202051')
->setBic('BYLADEM1001')
->setBank('Deutsche Kreditbank')
->setHolder('Erika Mustermann')
)
;
$formData = FinancialDataDto::fromTeamer($teamer);
$this->assertSame('DE02120300000000202051', $formData->getIban());
$this->assertSame('BYLADEM1001', $formData->getBic());
$this->assertSame('Deutsche Kreditbank', $formData->getBank());
$this->assertSame('Erika Mustermann', $formData->getHolder());
}
private function validSubmission(): array
{
return [
'taxId' => '12345678901',
'iban' => 'DE02120300000000202051',
'bic' => 'BYLADEM1001',
'bank' => 'Deutsche Kreditbank',
'holder' => 'Erika Mustermann',
];
}
private function createForm(FinancialDataDto $formData): FormInterface
{
self::bootKernel();
/** @var FormFactoryInterface $formFactory */
$formFactory = self::getContainer()->get(FormFactoryInterface::class);
return $formFactory->create(FinancialDataType::class, $formData, [
'csrf_protection' => false,
]);
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace App\Tests\Form;
use App\Entity\Teamer;
use App\Entity\User;
use App\Form\PersonalDataConfirmationType;
use App\Model\PersonalDataConfirmationDto;
use App\RequiredTeamerCheck\PersonalDataVerificationRequiredCheck;
use App\RequiredTeamerCheck\RecurringDeadlines;
use Carbon\CarbonImmutable;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
class PersonalDataConfirmationTypeTest extends KernelTestCase
{
protected function setUp(): void
{
CarbonImmutable::setTestNow();
}
protected function tearDown(): void
{
CarbonImmutable::setTestNow();
}
/**
* The invariant that keeps registry order out of the critical path: this check's
* own page must clear this check, no matter what else the teamer is missing.
* Previously verification lived on the profile form, whose 'profile' group also
* demands photo, language, health insurance, address and DOB — so a teamer in
* this state could never get past it.
*/
public function testConfirmingClearsTheCheckForAnOtherwiseIncompleteTeamer(): void
{
CarbonImmutable::setTestNow('2026-08-10 12:00:00');
$teamer = (new Teamer())->setCreatedAt(new \DateTimeImmutable('2023-10-11 16:29:04'));
$user = (new User())
->setRoles(['ROLE_TEAMER'])
->setTeamer($teamer)
;
$check = new PersonalDataVerificationRequiredCheck(new RecurringDeadlines(['04-01', '10-01']));
$this->assertFalse($check->isSatisfied($user));
$form = $this->createForm();
$form->submit(['confirmed' => '1']);
$this->assertTrue($form->isValid());
// what PersonalDataController does on a valid submit
$teamer->setDataVerifiedAt(new \DateTimeImmutable('2026-08-10 12:00:00'));
$this->assertTrue($check->isSatisfied($user));
$this->assertNull($teamer->getPhoto());
$this->assertNull($teamer->getLanguage());
$this->assertNull($teamer->getHealthInsuranceCompany());
}
public function testAnUntickedBoxIsRejected(): void
{
$form = $this->createForm();
$form->submit(['confirmed' => null]);
$this->assertFalse($form->isValid());
$this->assertCount(1, $form->get('confirmed')->getErrors());
}
private function createForm(): FormInterface
{
self::bootKernel();
/** @var FormFactoryInterface $formFactory */
$formFactory = self::getContainer()->get(FormFactoryInterface::class);
return $formFactory->create(PersonalDataConfirmationType::class, new PersonalDataConfirmationDto(), [
'csrf_protection' => false,
]);
}
}