94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
use App\Entity\Application;
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Disposition;
|
|
use App\Entity\Teamer;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* A called-off teamer is free again: the teamer views ask the assignment for the teamer's
|
|
* disposition to decide between "eingeteilt" and the application button, so a called-off
|
|
* disposition must not be handed out there.
|
|
*/
|
|
class AssignmentTest extends TestCase
|
|
{
|
|
public function testTheActiveDispositionOfATeamerIsReturned(): void
|
|
{
|
|
$assignment = new Assignment();
|
|
$teamer = new Teamer();
|
|
$disposition = $this->createDisposition($assignment, $teamer);
|
|
|
|
$this->assertSame($disposition, $assignment->getActiveDispositionByTeamer($teamer));
|
|
}
|
|
|
|
public function testACalledOffDispositionIsNotReturned(): void
|
|
{
|
|
$assignment = new Assignment();
|
|
$teamer = new Teamer();
|
|
|
|
$this
|
|
->createDisposition($assignment, $teamer)
|
|
->setStatus(Disposition::STATUS_CALLED_OFF)
|
|
;
|
|
|
|
$this->assertNull($assignment->getActiveDispositionByTeamer($teamer));
|
|
}
|
|
|
|
public function testTheDispositionOfAnotherTeamerIsNotReturned(): void
|
|
{
|
|
$assignment = new Assignment();
|
|
$this->createDisposition($assignment, new Teamer());
|
|
|
|
$this->assertNull($assignment->getActiveDispositionByTeamer(new Teamer()));
|
|
}
|
|
|
|
/**
|
|
* A teamer can be called off and disposed again on the same assignment, so both dispositions
|
|
* live side by side - the active one has to win.
|
|
*/
|
|
public function testTheActiveDispositionWinsOverACalledOffOne(): void
|
|
{
|
|
$assignment = new Assignment();
|
|
$teamer = new Teamer();
|
|
|
|
$this
|
|
->createDisposition($assignment, $teamer)
|
|
->setStatus(Disposition::STATUS_CALLED_OFF)
|
|
;
|
|
$disposition = $this->createDisposition($assignment, $teamer);
|
|
|
|
$this->assertSame($disposition, $assignment->getActiveDispositionByTeamer($teamer));
|
|
}
|
|
|
|
/**
|
|
* The "Busbegleitung ab" field stores 0 for "Keine Busbegleitung" as well as null.
|
|
*/
|
|
#[DataProvider('providePickups')]
|
|
public function testHasBusEscort(int|string|null $pickup, bool $expected): void
|
|
{
|
|
$this->assertSame($expected, (new Assignment())->setPickup($pickup)->hasBusEscort());
|
|
}
|
|
|
|
public static function providePickups(): iterable
|
|
{
|
|
yield 'none' => [null, false];
|
|
yield 'zero' => [0, false];
|
|
yield 'empty form value' => ['', false];
|
|
yield 'pickup' => [4711, true];
|
|
}
|
|
|
|
private function createDisposition(Assignment $assignment, Teamer $teamer): Disposition
|
|
{
|
|
$disposition = new Disposition(new Application($assignment, $teamer));
|
|
$assignment->addDisposition($disposition);
|
|
|
|
return $disposition;
|
|
}
|
|
}
|