Files
laraundfelix/tests/Feature/RegistrationTest.php
T
LarsandClaude Sonnet 5.5 8ecc1ecdaa
CI Feature / test (push) Successful in 2m42s
Deploy Test / test (push) Successful in 2m50s
Deploy Test / deploy (push) Successful in 28s
Verlinke Anmeldung und Registrierung gegenseitig
Die Anmeldeseite wies Neukunden nicht auf die Registrierung hin und die
Registrierungsseite nicht auf die Anmeldung. Beide Seiten verlinken sich
jetzt, mit Feature-Tests.

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

148 lines
5.0 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('Guten Tag');
$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_login_page_points_new_visitors_to_registration(): void
{
$this->get('/anmelden')
->assertOk()
->assertSee('Noch kein Konto?')
->assertSee('href="'.route('register').'"', false);
}
public function test_registration_page_points_existing_members_to_login(): void
{
$this->get('/registrieren')
->assertOk()
->assertSee('Schon registriert?')
->assertSee('href="'.route('login').'"', false);
}
public function test_guests_cannot_open_the_member_area(): void
{
$this->get('/bereich')->assertRedirect('/anmelden');
$this->get('/bereich/berechtigungen')->assertRedirect('/anmelden');
}
}