30]); SystemSettings::save(['fewo.spam.total_per_hour' => '120']); $this->assertSame(120, config('fewo.spam.total_per_hour')); $this->assertSame(120, SystemSettings::get('fewo.spam.total_per_hour')); SystemSettings::save(['fewo.spam.total_per_hour' => '']); config(['fewo.spam.total_per_hour' => 30]); SystemSettings::apply(); $this->assertSame(30, config('fewo.spam.total_per_hour'), 'Leer = der Wert der .env gilt wieder.'); $this->assertSame(0, SystemSetting::query()->count()); } public function test_a_secret_is_stored_encrypted(): void { SystemSettings::save(['mail.mailers.smtp.password' => 'geheim']); $stored = DB::table('system_settings')->where('key', 'mail.mailers.smtp.password')->first(); $this->assertNotSame('geheim', $stored?->value); $this->assertTrue((bool) $stored?->is_secret); $this->assertSame('geheim', SystemSettings::get('mail.mailers.smtp.password')); } /** * The whole point of the ceiling: what the operator sets here binds every landlord. */ public function test_the_stored_limit_becomes_the_ceiling_for_a_landlord(): void { config(['fewo.guest_retention_years' => 10]); SystemSettings::save(['fewo.guest_retention_years' => '4']); $tenant = Tenant::factory()->create(['guest_retention_years' => 9]); app(TenantContext::class)->set($tenant); app(TenantConfig::class)->refresh(); $this->assertSame(4, config('fewo.guest_retention_years'), 'Der Mandant darf die Obergrenze nicht überschreiten.'); } public function test_the_operator_edits_the_settings_and_a_landlords_administrator_cannot_reach_the_page(): void { $tenant = Tenant::factory()->create(); app(TenantContext::class)->set($tenant); $admin = User::factory()->create(); $this->actingAs($admin)->get('/betreiber/einstellungen')->assertForbidden(); $admin->forceFill(['is_operator' => true])->saveQuietly(); $this->actingAs($admin); Filament::setCurrentPanel('operator'); $this->get('/betreiber/einstellungen')->assertOk()->assertSee('Systemweite Einstellungen'); Livewire::test(SystemSettingsPage::class) ->set('data.fewo__spam__total_per_hour', '77') ->set('data.fewo__mail_redirect_to', 'auffang@example.com') ->call('save') ->assertHasNoErrors(); $this->assertSame(77, SystemSettings::get('fewo.spam.total_per_hour')); $this->assertSame('auffang@example.com', config('fewo.mail_redirect_to')); } /** * The hard redirect is the net that keeps a test server from writing to real guests. It is editable on * purpose, so it must be obvious that emptying it hands the decision back to each landlord. */ public function test_emptying_the_hard_redirect_leaves_only_the_landlords_own_test_mode(): void { SystemSettings::save(['fewo.mail_redirect_to' => 'auffang@example.com']); $live = Tenant::factory()->create(['operating_mode' => 'live', 'notification_emails' => 'wirt@example.com']); app(TenantContext::class)->set($live); $this->assertSame('auffang@example.com', Settings::mailRedirect()); SystemSettings::save(['fewo.mail_redirect_to' => '']); $this->assertNull(Settings::mailRedirect(), 'Ohne harte Umleitung entscheidet der Mandant allein.'); } }