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

48 lines
1.4 KiB
PHP
Raw Normal View History

2026-05-05 07:56:49 +00:00
<?php
namespace App\Tests\Controller\Admin;
use App\Entity\User;
2026-05-05 08:06:55 +00:00
use App\Tests\DatabaseWebTestCase;
2026-05-05 07:56:49 +00:00
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
2026-05-05 08:06:55 +00:00
final class AuthControllerTest extends DatabaseWebTestCase
2026-05-05 07:56:49 +00:00
{
public function testAdminRedirectsToLogin(): void
{
$this->client->request('GET', '/admin');
self::assertResponseRedirects('/admin/login');
}
public function testAdminCanLogin(): void
{
$container = static::getContainer();
$user = (new User())->setUsername('admin');
$hash = $container->get(UserPasswordHasherInterface::class)->hashPassword($user, 'secret-password');
$user->setPasswordHash($hash);
$this->entityManager->persist($user);
$this->entityManager->flush();
$crawler = $this->client->request('GET', '/admin/login');
$form = $crawler->selectButton('Sign in')->form([
'login_form[username]' => 'admin',
'login_form[password]' => 'secret-password',
]);
$this->client->submit($form);
self::assertResponseRedirects('/admin');
}
2026-05-05 08:57:14 +00:00
public function testLoginUsesUtilityAdminLayout(): void
{
$this->client->request('GET', '/admin/login');
self::assertSelectorExists('body.admin-auth');
self::assertSelectorExists('.admin-card');
self::assertSelectorExists('.button-primary');
}
2026-05-05 07:56:49 +00:00
}