Enth\u00e4lt gemischt: Laravel-10-Upgrade + Phase 1 (Contacts-Modul, Duplicats-Commands, Soft-Delete+Merge-Fields) + Phase 2 Code-Umstellungen (inquiry_id, $table='contacts'/'inquiries') + Offers-Modul (Migrationen, Models, offer_id in Booking, offer-Disk in filesystems.php). Phase 2 + Offers werden im folgenden Commit nach dev/backups/phase2-offers-2026-04-17/ verschoben, damit der Workspace auf Phase-1-only (= Test-System-Stand) reduziert ist und direkt auf Live deploybar wird. Tarball-Backup zus\u00e4tzlich unter: ../backups-safety/workspace-pre-phase1-rollback-2026-04-17.tar.gz Made-with: Cursor
99 lines
2.3 KiB
PHP
99 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use App\User;
|
|
use Tests\TestCase;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class LoginTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function testLoginPageIsAccessible(): void
|
|
{
|
|
$response = $this->get('/login');
|
|
|
|
$response->assertStatus(200);
|
|
}
|
|
|
|
public function testUnauthenticatedUserIsRedirectedToLogin(): void
|
|
{
|
|
$response = $this->get('/home');
|
|
|
|
$response->assertRedirect('/login');
|
|
}
|
|
|
|
public function testUserCanLoginWithValidCredentials(): void
|
|
{
|
|
$user = User::factory()->create([
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
|
|
$response = $this->post('/login', [
|
|
'email' => $user->email,
|
|
'password' => 'password',
|
|
]);
|
|
|
|
$this->assertAuthenticatedAs($user);
|
|
$response->assertRedirect();
|
|
}
|
|
|
|
public function testLoginFailsWithWrongPassword(): void
|
|
{
|
|
$user = User::factory()->create([
|
|
'password' => bcrypt('correct-password'),
|
|
]);
|
|
|
|
$response = $this->post('/login', [
|
|
'email' => $user->email,
|
|
'password' => 'wrong-password',
|
|
]);
|
|
|
|
$this->assertGuest();
|
|
$response->assertSessionHasErrors('email');
|
|
}
|
|
|
|
public function testLoginFailsWithUnknownEmail(): void
|
|
{
|
|
$response = $this->post('/login', [
|
|
'email' => 'nobody@example.com',
|
|
'password' => 'password',
|
|
]);
|
|
|
|
$this->assertGuest();
|
|
$response->assertSessionHasErrors('email');
|
|
}
|
|
|
|
public function testInactiveUserCannotLogin(): void
|
|
{
|
|
$user = User::factory()->inactive()->create([
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
|
|
$response = $this->post('/login', [
|
|
'email' => $user->email,
|
|
'password' => 'password',
|
|
]);
|
|
|
|
$this->assertGuest();
|
|
}
|
|
|
|
public function testAuthenticatedUserIsRedirectedAwayFromLoginPage(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->get('/login');
|
|
|
|
$response->assertRedirect();
|
|
}
|
|
|
|
public function testUserCanLogout(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$this->actingAs($user)->post('/logout');
|
|
|
|
$this->assertGuest();
|
|
}
|
|
}
|