feat: additional receipts as attachments to teamer invoices

addresses #869dv97u9
This commit is contained in:
2026-09-09 11:10:57 +02:00
parent 16d847137d
commit 52926ec6cc
29 changed files with 682 additions and 23 deletions
@@ -8,6 +8,7 @@ use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Disposition;
use App\Entity\Teamer;
use App\Entity\User;
use App\Security\Voter\DispositionVoter;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -85,6 +86,98 @@ class DispositionVoterTest extends TestCase
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->vote(DispositionVoter::CALL_OFF, $disposition));
}
/**
* The receipt window is the one permission in this voter that is not derived from a workflow
* transition, because there is none to derive it from: while the Honorarnote is being checked
* the state machine offers nothing at all, and that is exactly when receipts must stay
* manageable.
*
* @dataProvider receiptWindowStatuses
*/
public function testTheReceiptWindowIsTheTwoInvoiceStates(string $status, bool $expected): void
{
$this->security->method('isGranted')->willReturn(true);
$disposition = $this->createDisposition(skipFormalities: false)->setStatus($status);
$this->assertSame(
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
$this->vote(DispositionVoter::MANAGE_RECEIPTS, $disposition),
);
}
/**
* @return array<string, array{string, bool}>
*/
public static function receiptWindowStatuses(): array
{
return [
'invoice may still be uploaded' => [Disposition::STATUS_ENDED, true],
'invoice is being checked' => [Disposition::STATUS_CHECKING_INVOICE, true],
'nothing has happened yet' => [Disposition::STATUS_NEW, false],
'contract is being checked' => [Disposition::STATUS_CHECKING_CONTRACT, false],
'assignment is still ahead' => [Disposition::STATUS_CONFIRMED, false],
'invoice was accepted' => [Disposition::STATUS_COMPLETED, false],
'placement was cancelled' => [Disposition::STATUS_CALLED_OFF, false],
];
}
public function testReceiptsAreDeniedOnASkipFormalitiesAssignment(): void
{
$this->security->method('isGranted')->willReturn(true);
$disposition = $this
->createDisposition(skipFormalities: true)
->setStatus(Disposition::STATUS_CHECKING_INVOICE)
;
$this->assertSame(
VoterInterface::ACCESS_DENIED,
$this->vote(DispositionVoter::MANAGE_RECEIPTS, $disposition),
);
}
/**
* The owning teamer gets in without being administrative; anyone else's teamer does not.
*
* @dataProvider receiptOwnership
*/
public function testOnlyTheOwningTeamerMayManageTheirReceipts(bool $owning, bool $expected): void
{
$this->security
->method('isGranted')
->willReturnCallback(fn (string $role): bool => 'ROLE_TEAMER' === $role)
;
$teamer = new Teamer();
$assignment = (new Assignment())->setSkipFormalities(false);
$disposition = (new Disposition(new Application($assignment, $teamer)))
->setStatus(Disposition::STATUS_CHECKING_INVOICE)
;
$user = (new User())->setTeamer($owning ? $teamer : new Teamer());
$token = $this->createMock(TokenInterface::class);
$token->method('getUser')->willReturn($user);
$this->assertSame(
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
(new DispositionVoter($this->security))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
);
}
/**
* @return array<string, array{bool, bool}>
*/
public static function receiptOwnership(): array
{
return [
'their own placement' => [true, true],
'somebody else\'s placement' => [false, false],
];
}
private function vote(string $attribute, Disposition $disposition): int
{
return (new DispositionVoter($this->security))->vote(