Files
laraundfelix/tests/Feature/RegistrationTest.php
T
LarsandClaude Sonnet 5.5 2e6260acca Gestalte den Mitgliederbereich nach Brand-UI-Kit 14 neu
Eine Navigation (Meine Bibliothek, Programme, Meine Lizenzen, Konto-Menü) mit der freigegebenen Wortmarke,
Startseite ohne erfundene Inhalte, Bibliothek mit Inhaltsart-Filter und einer Karte je Medienidentität
(„Verwendet in“), Programm-/Moduldetail, Film und Material im Zusammenhang mit Begleitmaterial und Weg zurück,
Lizenzübersicht mit Detailseite je Berechtigung. Alle Größen aus der Größenskala (ADR-44, neues Token --card-min).

Tests bewusst angepasst: Der Film spielt auf der Kontextseite statt eingebettet im Programm, Download-Links tragen
ein Symbol, der Platzhalter ist ein dekoratives Element, die Wortmarke ist das freigegebene Logo. Die Vorschau der
Bibliothekskarte in der Verwaltung nutzt dieselbe Komponente.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 17:56:16 +01:00

132 lines
4.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use App\Notifications\VerifyEmailAddress;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
public function test_registration_requires_an_adult_confirmation(): void
{
$response = $this->from('/registrieren')->post('/registrieren', [
'name' => 'Ada Trainer',
'email' => 'ada@example.com',
'password' => 'password-pass',
'password_confirmation' => 'password-pass',
]);
$response->assertRedirect('/registrieren');
$response->assertSessionHasErrors('adult');
$this->assertDatabaseCount('users', 0);
}
public function test_registration_creates_a_person_and_sends_verification(): void
{
Notification::fake();
$response = $this->post('/registrieren', [
'name' => 'Ada Trainer',
'email' => 'ada@example.com',
'password' => 'password-pass',
'password_confirmation' => 'password-pass',
'adult' => '1',
]);
$response->assertRedirect(route('verification.notice'));
$user = User::query()->where('email', 'ada@example.com')->first();
$this->assertNotNull($user);
$this->assertNotNull($user->confirmed_adult_at);
$this->assertSame('person', $user->party->type->value);
$this->assertSame('private', $user->party->profile->visibility['display_name']);
$this->assertAuthenticatedAs($user);
Notification::assertSentTo($user, VerifyEmailAddress::class);
}
public function test_placeholder_app_url_uses_the_address_opened_in_the_browser(): void
{
Notification::fake();
config(['app.url' => 'https://CHANGE-ME.example']);
$response = $this->post('/registrieren', [
'name' => 'Probe Mitglied',
'email' => 'probe@example.test',
'password' => 'password-pass',
'password_confirmation' => 'password-pass',
'adult' => '1',
]);
$response->assertRedirect(url('/email/bestaetigen'));
$user = User::query()->where('email', 'probe@example.test')->firstOrFail();
Notification::assertSentTo($user, VerifyEmailAddress::class, function (VerifyEmailAddress $notification) use ($user): bool {
$link = $notification->toMail($user)->actionUrl;
$path = parse_url($link, PHP_URL_PATH);
$query = parse_url($link, PHP_URL_QUERY);
$this->actingAs($user)
->get($path.'?'.$query)
->assertRedirect(route('member.dashboard'));
return str_starts_with($link, url('/email/bestaetigen/'))
&& ! str_contains($link, 'CHANGE-ME.example');
});
}
public function test_verified_member_can_log_in_and_reaches_the_dashboard(): void
{
$user = User::factory()->create([
'email' => 'ada@example.com',
'password' => 'password-pass',
]);
$response = $this->post('/anmelden', [
'email' => 'ada@example.com',
'password' => 'password-pass',
]);
$response->assertRedirect(route('member.dashboard'));
$this->assertAuthenticatedAs($user);
$this->get('/bereich')->assertOk()->assertSee('Willkommen zurück, '.$user->name, false);
$this->get('/bereich/bibliothek')->assertOk()->assertSee('Noch nichts in der Bibliothek');
}
public function test_unverified_member_cannot_open_the_member_area(): void
{
$user = User::factory()->unverified()->create([
'password' => 'password-pass',
]);
$this->post('/anmelden', [
'email' => $user->email,
'password' => 'password-pass',
])->assertRedirect(route('member.dashboard'));
$this->get('/bereich')->assertRedirect(route('verification.notice'));
}
public function test_password_reset_sends_a_link(): void
{
Notification::fake();
$user = User::factory()->create();
$this->post('/passwort/vergessen', ['email' => $user->email])
->assertSessionHas('status');
Notification::assertSentTo($user, ResetPassword::class);
}
public function test_guests_cannot_open_the_member_area(): void
{
$this->get('/bereich')->assertRedirect('/anmelden');
$this->get('/bereich/berechtigungen')->assertRedirect('/anmelden');
}
}