Files
fotospiel-app/tests/Feature/RegistrationTest.php
Codex Agent d04e234ca0 - Tenant-Admin-PWA: Neues /event-admin/welcome Onboarding mit WelcomeHero, Packages-, Order-Summary- und Event-Setup-Pages, Zustandsspeicher, Routing-Guard und Dashboard-CTA für Erstnutzer; Filament-/admin-Login via Custom-View behoben.
- Brand/Theming: Marketing-Farb- und Typographievariablen in `resources/css/app.css` eingeführt, AdminLayout, Dashboardkarten und Onboarding-Komponenten entsprechend angepasst; Dokumentation (`docs/todo/tenant-admin-onboarding-fusion.md`, `docs/changes/...`) aktualisiert.
- Checkout & Payments: Checkout-, PayPal-Controller und Tests für integrierte Stripe/PayPal-Flows sowie Paket-Billing-Abläufe überarbeitet; neue PayPal SDK-Factory und Admin-API-Helper (`resources/js/admin/api.ts`) schaffen Grundlage für Billing/Members/Tasks-Seiten.
- DX & Tests: Neue Playwright/E2E-Struktur (docs/testing/e2e.md, `tests/e2e/tenant-onboarding-flow.test.ts`, Utilities), E2E-Tenant-Seeder und zusätzliche Übersetzungen/Factories zur Unterstützung der neuen Flows.
- Marketing-Kommunikation: Automatische Kontakt-Bestätigungsmail (`ContactConfirmation` + Blade-Template) implementiert; Guest-PWA unter `/event` erreichbar.
- Nebensitzung: Blogsystem gefixt und umfassenden BlogPostSeeder für Beispielinhalte angelegt.
2025-10-10 21:31:55 +02:00

172 lines
5.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Mail\Welcome;
use App\Models\Package;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
private function captureLocation($response): string
{
$redirect = $response->headers->get('Location');
$location = $redirect ?? $response->headers->get('X-Inertia-Location');
return $location ?? '';
}
public function test_registration_creates_user_and_tenant(): void
{
$freePackage = Package::factory()->create(['price' => 0]);
$response = $this->post(route('register.store'), [
'username' => 'testuser',
'email' => 'test@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
'first_name' => 'Test',
'last_name' => 'User',
'address' => 'Test Address',
'phone' => '123456789',
'privacy_consent' => true,
'package_id' => $freePackage->id,
]);
$location = $this->captureLocation($response);
$expected = route('dashboard', absolute: false);
$this->assertNotEmpty($location);
$this->assertTrue($location === $expected || Str::endsWith($location, $expected));
$this->assertDatabaseHas('users', [
'username' => 'testuser',
'email' => 'test@example.com',
'first_name' => 'Test',
'last_name' => 'User',
'address' => 'Test Address',
'phone' => '123456789',
'role' => 'tenant_admin',
]);
$user = User::where('email', 'test@example.com')->first();
$this->assertNotNull($user->tenant);
$this->assertDatabaseHas('tenants', [
'user_id' => $user->id,
'name' => 'Test User',
]);
$this->assertDatabaseHas('tenant_packages', [
'tenant_id' => $user->tenant->id,
'package_id' => $freePackage->id,
]);
}
public function test_registration_without_package_assigns_tenant_only(): void
{
$response = $this->post(route('register.store'), [
'username' => 'testuser2',
'email' => 'test2@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
'first_name' => 'Test',
'last_name' => 'User',
'address' => 'Test Address',
'phone' => '123456789',
'privacy_consent' => true,
]);
$location = $this->captureLocation($response);
$expected = route('dashboard', absolute: false);
$this->assertNotEmpty($location);
$this->assertTrue($location === $expected || Str::endsWith($location, $expected));
$user = User::where('email', 'test2@example.com')->first();
$this->assertNotNull($user->tenant);
$this->assertDatabaseHas('users', [
'email' => 'test2@example.com',
'role' => 'user',
]);
$this->assertDatabaseMissing('tenant_packages', [
'tenant_id' => $user->tenant->id,
]);
}
public function test_registration_validation_fails(): void
{
$response = $this->post(route('register.store'), [
'username' => '',
'email' => 'invalid',
'password' => 'short',
'password_confirmation' => 'different',
'first_name' => '',
'last_name' => '',
'address' => '',
'phone' => '',
'privacy_consent' => false,
]);
$response->assertSessionHasErrors([
'username', 'email', 'password', 'first_name', 'last_name', 'address', 'phone', 'privacy_consent',
]);
}
public function test_registration_with_paid_package_redirects_to_checkout_flow(): void
{
$paidPackage = Package::factory()->create(['price' => 10.00]);
$response = $this->post(route('register.store'), [
'username' => 'paiduser',
'email' => 'paid@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
'first_name' => 'Paid',
'last_name' => 'User',
'address' => 'Paid Address',
'phone' => '123456789',
'privacy_consent' => true,
'package_id' => $paidPackage->id,
]);
$response->assertRedirect(route('marketing.buy', $paidPackage->id));
$this->assertDatabaseHas('users', [
'username' => 'paiduser',
'email' => 'paid@example.com',
'role' => 'user',
]);
}
public function test_registered_event_sends_welcome_email(): void
{
Mail::fake();
$freePackage = Package::factory()->create(['price' => 0]);
$this->post(route('register.store'), [
'username' => 'testuser3',
'email' => 'test3@example.com',
'password' => 'Password123!',
'password_confirmation' => 'Password123!',
'first_name' => 'Test',
'last_name' => 'User',
'address' => 'Test Address',
'phone' => '123456789',
'privacy_consent' => true,
'package_id' => $freePackage->id,
]);
Mail::assertQueued(Welcome::class, function ($mail) {
return $mail->hasTo('test3@example.com');
});
}
}