62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Security\Voter;
|
|
|
|
use App\Entity\Application;
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Disposition;
|
|
use App\Entity\Teamer;
|
|
use App\Security\Voter\ApplicationVoter;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
|
|
|
/**
|
|
* A called-off placement frees its place. Counting it would leave the office with raising
|
|
* availableDispositions as the only way to re-staff - which adds a place to the n8n feed, where a
|
|
* place is a row the Wechselpass hangs off.
|
|
*/
|
|
class ApplicationVoterTest extends TestCase
|
|
{
|
|
public function testACalledOffPlaceCanBeStaffedAgain(): void
|
|
{
|
|
$assignment = (new Assignment())->setAvailableDispositions(2);
|
|
$this->dispose($assignment);
|
|
$this->dispose($assignment)->setStatus(Disposition::STATUS_CALLED_OFF);
|
|
|
|
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->voteDispose($assignment));
|
|
}
|
|
|
|
public function testAFullAssignmentCannotBeStaffed(): void
|
|
{
|
|
$assignment = (new Assignment())->setAvailableDispositions(2);
|
|
$this->dispose($assignment);
|
|
$this->dispose($assignment);
|
|
|
|
$this->assertSame(VoterInterface::ACCESS_DENIED, $this->voteDispose($assignment));
|
|
}
|
|
|
|
private function dispose(Assignment $assignment): Disposition
|
|
{
|
|
$disposition = new Disposition(new Application($assignment, new Teamer()));
|
|
$assignment->addDisposition($disposition);
|
|
|
|
return $disposition;
|
|
}
|
|
|
|
private function voteDispose(Assignment $assignment): int
|
|
{
|
|
$security = $this->createStub(Security::class);
|
|
$security->method('isGranted')->willReturnCallback(fn (string $role) => 'ROLE_ADMINISTRATIVE' === $role);
|
|
|
|
return (new ApplicationVoter($security))->vote(
|
|
$this->createStub(TokenInterface::class),
|
|
new Application($assignment, new Teamer()),
|
|
[ApplicationVoter::DISPOSE],
|
|
);
|
|
}
|
|
}
|