83 lines
3.0 KiB
PHP
83 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Repository;
|
|
|
|
use App\Model\TeamerFilterDto;
|
|
use App\Repository\TeamerRepository;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
/**
|
|
* The all-season list is the ordinary teamer list under a scope, so what separates the two is a
|
|
* single condition in the shared query builder. Compiled here so the scope cannot quietly stop
|
|
* being applied - an unscoped "Saisonteamer" list would silently show the whole team.
|
|
*/
|
|
class TeamerRepositoryTest extends KernelTestCase
|
|
{
|
|
public function testTheScopedListRestrictsToAllSeasonTeamers(): void
|
|
{
|
|
$query = $this->getRepository()->getListQuery((new TeamerFilterDto())->setAllSeason(true));
|
|
|
|
$this->assertStringContainsString('teamer.allSeason = :allSeason', $query->getDQL());
|
|
$this->assertTrue($query->getParameter('allSeason')->getValue());
|
|
}
|
|
|
|
public function testTheGeneralListIsNotRestricted(): void
|
|
{
|
|
$query = $this->getRepository()->getListQuery(new TeamerFilterDto());
|
|
|
|
$this->assertStringNotContainsString('teamer.allSeason', $query->getDQL());
|
|
$this->assertNull($query->getParameter('allSeason'));
|
|
}
|
|
|
|
/**
|
|
* The mailing resolves its recipients through the same builder, so a mailing started from
|
|
* the all-season list must not be able to reach the rest of the team.
|
|
*/
|
|
public function testTheMailingRecipientsCarryTheSameScope(): void
|
|
{
|
|
$repository = $this->getRepository();
|
|
|
|
$reflection = new \ReflectionMethod($repository, 'createListQueryBuilder');
|
|
$queryBuilder = $reflection->invoke($repository, (new TeamerFilterDto())->setAllSeason(true));
|
|
|
|
$this->assertStringContainsString('teamer.allSeason = :allSeason', $queryBuilder->getDQL());
|
|
}
|
|
|
|
/**
|
|
* The season assignment form picks its teamer through this endpoint, so an unrestricted
|
|
* suggestion list would let an admin place a short term teamer on a season assignment.
|
|
*/
|
|
public function testTheAutocompleteCanBeRestrictedToAllSeasonTeamers(): void
|
|
{
|
|
$dql = $this->createAutocompletionQueryBuilder(true)->getDQL();
|
|
|
|
$this->assertStringContainsString('teamer.allSeason = :allSeason', $dql);
|
|
}
|
|
|
|
public function testTheAutocompleteIsUnrestrictedByDefault(): void
|
|
{
|
|
$dql = $this->createAutocompletionQueryBuilder(false)->getDQL();
|
|
|
|
$this->assertStringNotContainsString('teamer.allSeason', $dql);
|
|
$this->assertStringContainsString('teamer.deletedAt IS NULL', $dql);
|
|
}
|
|
|
|
private function createAutocompletionQueryBuilder(bool $allSeasonOnly): QueryBuilder
|
|
{
|
|
$repository = $this->getRepository();
|
|
$reflection = new \ReflectionMethod($repository, 'createAutocompletionQueryBuilder');
|
|
|
|
return $reflection->invoke($repository, '', $allSeasonOnly);
|
|
}
|
|
|
|
private function getRepository(): TeamerRepository
|
|
{
|
|
self::bootKernel();
|
|
|
|
return self::getContainer()->get(TeamerRepository::class);
|
|
}
|
|
}
|