132 lines
4.5 KiB
PHP
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('Guten Tag');
|
|
$this->get('/bereich/bibliothek')->assertOk()->assertSee('Noch kein Kurs');
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|