1
0
Fork 0
get-installer-bootstrap/tests/Controller/Admin/SettingsControllerTest.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2026-05-05 08:28:06 +00:00
<?php
namespace App\Tests\Controller\Admin;
use App\Entity\AppSetting;
use App\Entity\User;
use App\Tests\DatabaseWebTestCase;
final class SettingsControllerTest extends DatabaseWebTestCase
{
public function testSettingsRequireAuthentication(): void
{
$this->client->request('GET', '/admin/settings');
self::assertResponseRedirects('/admin/login');
}
public function testAdminCanUpdateRootRedirectUrl(): void
{
$this->loginAsAdmin();
$crawler = $this->client->request('GET', '/admin/settings');
$form = $crawler->selectButton('Enregistrer')->form([
'settings[rootRedirectUrl]' => 'https://example.com/installers',
]);
$this->client->submit($form);
self::assertResponseRedirects('/admin');
self::assertSame(
'https://example.com/installers',
$this->entityManager->getRepository(AppSetting::class)->getValue(AppSetting::ROOT_REDIRECT_URL)
);
}
public function testRootRedirectUrlMustBeHttpOrHttps(): void
{
$this->loginAsAdmin();
$crawler = $this->client->request('GET', '/admin/settings');
$form = $crawler->selectButton('Enregistrer')->form([
'settings[rootRedirectUrl]' => 'javascript:alert(1)',
]);
$this->client->submit($form);
self::assertResponseStatusCodeSame(422);
self::assertNull($this->entityManager->getRepository(AppSetting::class)->getValue(AppSetting::ROOT_REDIRECT_URL));
}
private function loginAsAdmin(): void
{
$user = (new User())->setUsername('admin')->setPasswordHash('unused');
$this->entityManager->persist($user);
$this->entityManager->flush();
$this->client->loginUser($user);
}
}