Files
myep-team/tests/Controller/Admin/ApplicationFormSubmission/CreateTeamerControllerTest.php
T

119 lines
4.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Controller\Admin\ApplicationFormSubmission;
use App\Entity\ApplicationFormSubmission;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
/**
* The feature gate, which is the only part of provisioning a test can exercise: everything behind
* it writes to the production CRM, where the teamer selection is changeable - the test database
* answers aenderbar="False" for it (.ddev/plans/buspro-crm-selection-write.md).
*
* With the flag off the route must not exist at all, not merely hide its button: the modal is
* reachable by url, and a reviewer who bookmarked it would otherwise write to BusPro from a
* release where the feature is meant to be dormant.
*/
class CreateTeamerControllerTest extends WebTestCase
{
private KernelBrowser $client;
private EntityManagerInterface $entityManager;
protected function setUp(): void
{
$this->client = static::createClient(server: ['HTTPS' => true]);
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
$this->entityManager->createQuery(sprintf('DELETE FROM %s', ApplicationFormSubmission::class))->execute();
$this->entityManager->createQuery(sprintf('DELETE FROM %s', User::class))->execute();
$this->client->loginUser($this->reviewer());
}
public function testTheDisabledFeatureHidesTheRouteEntirely(): void
{
$this->client->request('GET', $this->url());
$this->assertSame(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
}
/**
* The POST is the one that writes, so it is pinned separately rather than trusted to share the
* guard with the GET.
*/
public function testTheDisabledFeatureRefusesThePostAsWell(): void
{
$this->client->request('POST', $this->url());
$this->assertSame(Response::HTTP_NOT_FOUND, $this->client->getResponse()->getStatusCode());
$this->assertNull($this->submission()->getTeamerCreatedAt());
}
public function testTheDetailPageOffersNoProvisioningWhileTheFeatureIsOff(): void
{
$crawler = $this->client->request(
'GET',
sprintf('/admin/application-form-submission/detail/%s', $this->submission()->getUuid())
);
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
$this->assertCount(0, $crawler->filter('button[hx-get*="create-teamer"]'));
}
private function url(): string
{
return sprintf('/admin/application-form-submission/create-teamer/%s', $this->submission()->getUuid());
}
private function submission(): ApplicationFormSubmission
{
$repository = $this->entityManager->getRepository(ApplicationFormSubmission::class);
$submission = $repository->findOneBy([], ['id' => 'DESC']);
if (null !== $submission) {
return $submission;
}
$submission = (new ApplicationFormSubmission(
'applicationform',
'Bewerbungsformular',
new \DateTimeImmutable('2026-09-22T12:30:00+02:00'),
'F'
))
->setFirstName('Anna')
->setLastName('Muster')
->setEmail('[email protected]')
->setBirthDate('1990-01-01')
;
$this->entityManager->persist($submission);
$this->entityManager->flush();
return $submission;
}
private function reviewer(): User
{
$user = (new User())
->setFirstName('Rita')
->setLastName('Reviewer')
->setEmail('[email protected]')
->setRoles(['ROLE_TEAM_ADMIN'])
->setBusProAddressId(1)
->setBusProPersonId(1)
;
$this->entityManager->persist($user);
$this->entityManager->flush();
return $user;
}
}