massive improvements to tests, streamlined and synced migrations, fixed a lot of wrong or old table field references. implemented a lot of pages in react for website frontend
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Tests\Feature\Auth;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
|
||||
class AuthenticationTest extends TestCase
|
||||
{
|
||||
@@ -22,7 +23,20 @@ class AuthenticationTest extends TestCase
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'login' => $user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
public function test_users_can_authenticate_with_username()
|
||||
{
|
||||
$user = User::factory()->create(['username' => 'testuser']);
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'testuser',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
@@ -34,12 +48,29 @@ class AuthenticationTest extends TestCase
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$this->assertGuest();
|
||||
$response->assertRedirect(route('login', absolute: false));
|
||||
$response->assertSessionHasErrors(['login' => 'Diese Anmeldedaten wurden nicht gefunden.']);
|
||||
}
|
||||
|
||||
public function test_login_redirects_unverified_user_to_verification_notice()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => $user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('verification.notice', absolute: false));
|
||||
}
|
||||
|
||||
public function test_users_can_logout()
|
||||
@@ -49,7 +80,7 @@ class AuthenticationTest extends TestCase
|
||||
$response = $this->actingAs($user)->post(route('logout'));
|
||||
|
||||
$this->assertGuest();
|
||||
$response->assertRedirect(route('home'));
|
||||
$response->assertRedirect('/');
|
||||
}
|
||||
|
||||
public function test_users_are_rate_limited()
|
||||
@@ -57,23 +88,20 @@ class AuthenticationTest extends TestCase
|
||||
$user = User::factory()->create();
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
])->assertStatus(302)->assertSessionHasErrors([
|
||||
'email' => 'These credentials do not match our records.',
|
||||
]);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['login' => 'Diese Anmeldedaten wurden nicht gefunden.']);
|
||||
}
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'login' => $user->email,
|
||||
'password' => 'wrong-password',
|
||||
]);
|
||||
|
||||
$response->assertSessionHasErrors('email');
|
||||
|
||||
$errors = session('errors');
|
||||
|
||||
$this->assertStringContainsString('Too many login attempts', $errors->first('email'));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['login' => 'Zu viele Login-Versuche. Bitte versuche es in :seconds Sekunden erneut.']);
|
||||
}
|
||||
}
|
||||
|
||||
113
tests/Feature/Auth/LoginTest.php
Normal file
113
tests/Feature/Auth/LoginTest.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\VerifyEmail;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_successful_login_with_valid_credentials()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'valid@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'valid@example.com',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$this->assertEquals('valid@example.com', Auth::user()->email);
|
||||
}
|
||||
|
||||
public function test_successful_login_with_username()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'username' => 'validuser',
|
||||
'password' => bcrypt('password'),
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'validuser',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$this->assertEquals('validuser', Auth::user()->username);
|
||||
}
|
||||
|
||||
public function test_login_fails_with_invalid_credentials()
|
||||
{
|
||||
User::factory()->create([
|
||||
'email' => 'invalid@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'invalid@example.com',
|
||||
'password' => 'wrongpassword',
|
||||
]);
|
||||
|
||||
$this->assertGuest();
|
||||
$response->assertStatus(302);
|
||||
$response->assertRedirect(route('login', absolute: false));
|
||||
$response->assertSessionHasErrors(['login' => 'Diese Anmeldedaten wurden nicht gefunden.']);
|
||||
}
|
||||
|
||||
public function test_login_redirects_unverified_user_to_verification_notice()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'unverified@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'unverified@example.com',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('verification.notice', absolute: false));
|
||||
}
|
||||
|
||||
public function test_rate_limiting_on_failed_logins()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'ratelimit@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
// Simulate 5 failed attempts
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'ratelimit@example.com',
|
||||
'password' => 'wrongpassword',
|
||||
]);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['login' => 'Diese Anmeldedaten wurden nicht gefunden.']);
|
||||
}
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'ratelimit@example.com',
|
||||
'password' => 'wrongpassword',
|
||||
]);
|
||||
|
||||
$this->assertGuest();
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['login' => 'Zu viele Login-Versuche. Bitte versuche es in :seconds Sekunden erneut.']);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ namespace Tests\Feature\Auth;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use App\Models\Package;
|
||||
use App\Models\Tenant;
|
||||
|
||||
class RegistrationTest extends TestCase
|
||||
{
|
||||
@@ -18,14 +21,215 @@ class RegistrationTest extends TestCase
|
||||
|
||||
public function test_new_users_can_register()
|
||||
{
|
||||
$response = $this->post(route('register.store'), [
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'testuser',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
'password' => 'Password123!',
|
||||
'password_confirmation' => 'Password123!',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$this->assertDatabaseHas('users', [
|
||||
'email' => 'test@example.com',
|
||||
]);
|
||||
$this->assertDatabaseHas('tenants', [
|
||||
'user_id' => User::latest()->first()->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_with_free_package_assigns_tenant_package()
|
||||
{
|
||||
$freePackage = Package::factory()->endcustomer()->create(['price' => 0]);
|
||||
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'testuserfree',
|
||||
'email' => 'free@example.com',
|
||||
'password' => 'Password123!',
|
||||
'password_confirmation' => 'Password123!',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
'package_id' => $freePackage->id,
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$user = User::latest()->first();
|
||||
$tenant = Tenant::where('user_id', $user->id)->first();
|
||||
$this->assertDatabaseHas('tenant_packages', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $freePackage->id,
|
||||
'active' => true,
|
||||
'price' => 0,
|
||||
]);
|
||||
$this->assertDatabaseHas('package_purchases', [
|
||||
'tenant_id' => $tenant->id,
|
||||
'package_id' => $freePackage->id,
|
||||
'type' => 'endcustomer_event',
|
||||
'price' => 0,
|
||||
]);
|
||||
$this->assertEquals('active', $tenant->subscription_status);
|
||||
}
|
||||
|
||||
public function test_registration_with_paid_package_redirects_to_buy()
|
||||
{
|
||||
$paidPackage = Package::factory()->endcustomer()->create(['price' => 10]);
|
||||
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'testuserpaid',
|
||||
'email' => 'paid@example.com',
|
||||
'password' => 'Password123!',
|
||||
'password_confirmation' => 'Password123!',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
'package_id' => $paidPackage->id,
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('buy.packages', $paidPackage->id));
|
||||
$this->assertDatabaseHas('users', ['email' => 'paid@example.com']);
|
||||
// Package not assigned yet
|
||||
$this->assertDatabaseMissing('tenant_packages', ['package_id' => $paidPackage->id]);
|
||||
}
|
||||
|
||||
public function test_registration_fails_with_invalid_email()
|
||||
{
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'invaliduser',
|
||||
'email' => 'invalid-email',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['email' => 'Das E-Mail muss eine gültige E-Mail-Adresse sein.']);
|
||||
$this->assertDatabaseMissing('users', ['email' => 'invalid-email']);
|
||||
}
|
||||
|
||||
public function test_registration_fails_with_short_password()
|
||||
{
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'shortpass',
|
||||
'email' => 'short@example.com',
|
||||
'password' => 'short',
|
||||
'password_confirmation' => 'short',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['password' => 'Das Passwort muss mindestens 8 Zeichen lang sein.']);
|
||||
$this->assertDatabaseMissing('users', ['email' => 'short@example.com']);
|
||||
}
|
||||
|
||||
public function test_registration_fails_without_privacy_consent()
|
||||
{
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'noconsent',
|
||||
'email' => 'noconsent@example.com',
|
||||
'password' => 'Password123!',
|
||||
'password_confirmation' => 'Password123!',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => false,
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['privacy_consent' => 'Die Datenschutzbestätigung muss akzeptiert werden.']);
|
||||
$this->assertDatabaseMissing('users', ['email' => 'noconsent@example.com']);
|
||||
}
|
||||
|
||||
public function test_registration_fails_with_duplicate_email()
|
||||
{
|
||||
// Create existing user
|
||||
User::factory()->create(['email' => 'duplicate@example.com']);
|
||||
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Duplicate User',
|
||||
'username' => 'duplicate',
|
||||
'email' => 'duplicate@example.com',
|
||||
'password' => 'Password123!',
|
||||
'password_confirmation' => 'Password123!',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['email' => 'Das E-Mail wurde bereits verwendet.']);
|
||||
}
|
||||
|
||||
public function test_registration_fails_with_mismatched_passwords()
|
||||
{
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'mismatch',
|
||||
'email' => 'mismatch@example.com',
|
||||
'password' => 'Password123!',
|
||||
'password_confirmation' => 'different123!',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
]);
|
||||
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHasErrors(['password' => 'Das Passwort-Feld-Bestätigung stimmt nicht überein.']);
|
||||
$this->assertDatabaseMissing('users', ['email' => 'mismatch@example.com']);
|
||||
}
|
||||
|
||||
public function test_registration_with_invalid_package_id_uses_fallback()
|
||||
{
|
||||
$response = $this->post('/de/register', [
|
||||
'name' => 'Test User',
|
||||
'username' => 'invalidpkg',
|
||||
'email' => 'invalidpkg@example.com',
|
||||
'password' => 'Password123!',
|
||||
'password_confirmation' => 'Password123!',
|
||||
'first_name' => 'Max',
|
||||
'last_name' => 'Mustermann',
|
||||
'address' => 'Musterstr. 1',
|
||||
'phone' => '+49123456789',
|
||||
'privacy_consent' => true,
|
||||
'package_id' => 999, // Invalid ID
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$this->assertDatabaseHas('users', ['email' => 'invalidpkg@example.com']);
|
||||
// No package assigned
|
||||
$user = User::latest()->first();
|
||||
$tenant = Tenant::where('user_id', $user->id)->first();
|
||||
$this->assertDatabaseMissing('tenant_packages', ['tenant_id' => $tenant->id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class VerificationNotificationTest extends TestCase
|
||||
|
||||
$this->actingAs($user)
|
||||
->post(route('verification.send'))
|
||||
->assertRedirect(route('home'));
|
||||
->assertRedirect('/');
|
||||
|
||||
Notification::assertSentTo($user, VerifyEmail::class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user