108 lines
3.3 KiB
PHP
108 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Controller\Administrative\System;
|
|
|
|
use App\Entity\User;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* The settings overview replaced the settings submenu, so it is the only way to the settings
|
|
* pages: it has to list every page a role may open, and none it may not.
|
|
*/
|
|
class IndexControllerTest 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', User::class))->execute();
|
|
}
|
|
|
|
public function testAnAdminSeesEverySettingsPage(): void
|
|
{
|
|
$routes = $this->settingsRoutes(['ROLE_TEAM_ADMIN']);
|
|
|
|
$this->assertCount(15, $routes);
|
|
$this->assertContains('app_admin_system_user_index', $routes);
|
|
}
|
|
|
|
public function testAManagerSeesOnlyTheSharedSettingsPages(): void
|
|
{
|
|
$routes = $this->settingsRoutes(['ROLE_MANAGER']);
|
|
|
|
$this->assertCount(7, $routes);
|
|
|
|
foreach ($routes as $route) {
|
|
$this->assertStringStartsWith('app_administrative_system_', $route);
|
|
}
|
|
}
|
|
|
|
public function testEveryListedPageOpens(): void
|
|
{
|
|
$crawler = $this->request(['ROLE_TEAM_ADMIN']);
|
|
|
|
foreach ($crawler->filter('[data-qa-settings-page]')->extract(['href']) as $href) {
|
|
$this->client->request('GET', $href);
|
|
|
|
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode(), $href);
|
|
}
|
|
}
|
|
|
|
public function testTheUserMenuLinksTheOtherAreasButNotTheCurrentOne(): void
|
|
{
|
|
$crawler = $this->request(['ROLE_TEAM_ADMIN', 'ROLE_MANAGER']);
|
|
|
|
$labels = $crawler->filter('[role="menu"] a')->each(static fn (Crawler $link): string => trim($link->text()));
|
|
|
|
$this->assertContains('zum Managementbereich', $labels);
|
|
$this->assertNotContains('zum Adminbereich', $labels);
|
|
$this->assertContains('Logout', $labels);
|
|
}
|
|
|
|
/**
|
|
* @param list<string> $roles
|
|
*
|
|
* @return list<string>
|
|
*/
|
|
private function settingsRoutes(array $roles): array
|
|
{
|
|
return $this->request($roles)->filter('[data-qa-settings-page]')->extract(['data-qa-settings-page']);
|
|
}
|
|
|
|
/**
|
|
* @param list<string> $roles
|
|
*/
|
|
private function request(array $roles): Crawler
|
|
{
|
|
$user = (new User())
|
|
->setFirstName('Erika')
|
|
->setLastName('Einstellung')
|
|
->setEmail('[email protected]')
|
|
->setRoles($roles)
|
|
->setBusProAddressId(1)
|
|
->setBusProPersonId(1)
|
|
;
|
|
|
|
$this->entityManager->persist($user);
|
|
$this->entityManager->flush();
|
|
|
|
$this->client->loginUser($user);
|
|
$crawler = $this->client->request('GET', '/administrative/system');
|
|
|
|
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
|
|
|
|
return $crawler;
|
|
}
|
|
}
|