Files
myep-team/tests/Twig/TeamerStatusLabelTest.php
T

88 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Twig;
use App\Entity\Teamer;
use App\Entity\User;
use App\Twig\AppRuntime;
use PHPUnit\Framework\TestCase;
/**
* All-season is a flag on top of the status, not a status of its own: a teamer can be an
* all-season and an ordinary Bestandsteamer:in at the same time. The general Teamübersicht is
* the only place that overlap would otherwise be invisible, since both teamer lists render the
* same table and the status column never mentioned the flag.
*/
class TeamerStatusLabelTest extends TestCase
{
public function testAnAllSeasonTeamerKeepsTheirOrdinaryStatus(): void
{
$teamer = $this->createTeamer(Teamer::STATUS_EXISTING, true);
$this->assertSame('Bestandsteamer:in · Saison', $this->label($teamer));
}
public function testANewTeamerCanAlsoBeAllSeason(): void
{
$teamer = $this->createTeamer(Teamer::STATUS_NEW, true);
$this->assertSame('Neuteamer:in · Saison', $this->label($teamer));
}
public function testAnOrdinaryTeamerIsUnmarked(): void
{
$this->assertSame('Bestandsteamer:in', $this->label($this->createTeamer(Teamer::STATUS_EXISTING, false)));
$this->assertSame('Neuteamer:in', $this->label($this->createTeamer(Teamer::STATUS_NEW, false)));
}
/**
* A role replaces the status label entirely, but the flag is orthogonal to both - an admin
* who is also an all-season teamer has to stay recognisable as one.
*/
public function testARoleLabelStillCarriesTheMarker(): void
{
$teamer = $this->createTeamer(Teamer::STATUS_EXISTING, true);
$teamer->getUser()->setRoles(['ROLE_MANAGER']);
$this->assertSame('Reisemanagement · Saison', $this->label($teamer));
}
/**
* The dedicated Saisonteamer list is entirely all-season, so repeating it on every row
* would say nothing.
*/
public function testTheMarkerCanBeSuppressed(): void
{
$teamer = $this->createTeamer(Teamer::STATUS_EXISTING, true);
$this->assertSame('Bestandsteamer:in', $this->label($teamer, false));
}
private function label(Teamer $teamer, bool $includeAllSeason = true): string
{
return $this->createRuntime()->teamerStatusLabel($teamer, $includeAllSeason);
}
private function createTeamer(string $status, bool $allSeason): Teamer
{
$teamer = (new Teamer())
->setStatus($status)
->setAllSeason($allSeason)
;
// the label reads roles off the user, so every teamer needs one
(new User())->setTeamer($teamer);
return $teamer;
}
private function createRuntime(): AppRuntime
{
$reflection = new \ReflectionClass(AppRuntime::class);
return $reflection->newInstanceWithoutConstructor();
}
}