null, 'fewo.notification_email' => 'fewo@example.com']); $this->landlord(['notification_emails' => null, 'test_recipient' => null]); $this->assertFalse(Settings::isLive()); $this->assertSame('fewo@example.com', Settings::mailRedirect()); } public function test_in_test_mode_every_mail_goes_to_the_test_recipient_only(): void { config(['fewo.mail_redirect_to' => null, 'mail.default' => 'array']); $this->landlord(['operating_mode' => Settings::MODE_TEST, 'test_recipient' => 'test@example.com']); Mail::raw('Hallo', fn ($message) => $message->to('gast@example.com')->cc('vermieterin@example.com')->subject('Angebot')); $sent = app(MailManager::class)->mailer('array')->getSymfonyTransport()->messages()->last(); $this->assertSame(['test@example.com'], array_map(fn ($address) => $address->getAddress(), $sent->getEnvelope()->getRecipients())); } public function test_switched_live_mails_reach_their_real_recipients(): void { config(['fewo.mail_redirect_to' => null, 'mail.default' => 'array']); $this->landlord(['operating_mode' => Settings::MODE_LIVE]); Mail::raw('Hallo', fn ($message) => $message->to('gast@example.com')->subject('Angebot')); $sent = app(MailManager::class)->mailer('array')->getSymfonyTransport()->messages()->last(); $this->assertSame(['gast@example.com'], array_map(fn ($address) => $address->getAddress(), $sent->getEnvelope()->getRecipients())); $this->assertNull(Settings::mailRedirect()); } public function test_addresses_and_landlord_data_of_the_internal_communication_are_set_in_the_admin(): void { config(['fewo.mail_redirect_to' => null]); $this->seed(PropertySeeder::class); $tenant = Tenant::query()->where('slug', 'stommer')->firstOrFail(); app(TenantContext::class)->set($tenant); $this->actingAs(User::factory()->create()); Livewire::test(Operations::class) ->set('data.mode', Settings::MODE_LIVE) ->set('data.notification_recipients', ['brigitte@example.com', 'lars@example.com']) ->set('data.contact_email', 'info@example.com') ->set('data.sender_name', 'FeWo Test') ->set('data.sender_email', 'versand@example.com') ->set('data.owner_name', 'Brigitte Beispiel') ->set('data.bank_iban', 'DE02120300000000202051') ->call('save') ->assertHasNoErrors(); $this->assertSame(['brigitte@example.com', 'lars@example.com'], Settings::notificationRecipients()); $this->assertSame(['info@example.com', 'versand@example.com', 'FeWo Test'], [config('fewo.owner.email'), config('mail.from.address'), config('mail.from.name')]); $this->assertSame(['Brigitte Beispiel', 'DE02120300000000202051'], [config('fewo.owner.name'), config('fewo.bank.iban')]); Mail::fake(); $booking = app(CreateReservation::class)->handle(Property::sole(), new StayRequest(CarbonImmutable::parse('2026-12-01'), CarbonImmutable::parse('2026-12-05'), 2), ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.com']); Mail::assertSent(NewReservation::class, fn (NewReservation $mail): bool => $mail->hasTo('brigitte@example.com') && $mail->hasTo('lars@example.com')); Mail::assertSent(ReservationReceived::class, fn (ReservationReceived $mail): bool => $mail->hasReplyTo('info@example.com')); $this->assertNotNull($booking); } public function test_the_bank_details_are_stored_encrypted(): void { $tenant = $this->landlord(['bank_iban' => 'DE02120300000000202051']); $stored = DB::table('tenants')->where('id', $tenant->id)->value('bank_iban'); $this->assertNotSame('DE02120300000000202051', $stored); $this->assertSame('DE02120300000000202051', $tenant->fresh()->bank_iban); } public function test_a_landlord_cannot_relax_a_retention_period_or_the_bot_protection(): void { config(['fewo.guest_retention_years' => 10, 'fewo.spam.per_ip_per_hour' => 5, 'fewo.spam.min_seconds' => 4]); $this->landlord([ 'guest_retention_years' => 25, 'spam_per_ip_per_hour' => 50, 'spam_min_seconds' => 1, 'deposit_due_days' => 21, ]); $this->assertSame(10, config('fewo.guest_retention_years')); $this->assertSame(5, config('fewo.spam.per_ip_per_hour')); $this->assertSame(4, config('fewo.spam.min_seconds')); $this->assertSame(21, config('fewo.deposit_due_days')); } public function test_a_landlord_may_tighten_a_retention_period(): void { config(['fewo.guest_retention_years' => 10, 'fewo.spam.min_seconds' => 4]); $this->landlord(['guest_retention_years' => 3, 'spam_min_seconds' => 9]); $this->assertSame(3, config('fewo.guest_retention_years')); $this->assertSame(9, config('fewo.spam.min_seconds')); } public function test_invalid_notification_addresses_are_rejected(): void { $this->landlord(); $this->actingAs(User::factory()->create()); Livewire::test(Operations::class) ->set('data.notification_recipients', ['keine-adresse']) ->call('save') ->assertHasErrors(); } public function test_server_override_always_wins(): void { config(['fewo.mail_redirect_to' => 'server@example.com']); $this->landlord(['operating_mode' => Settings::MODE_LIVE]); $this->assertSame('server@example.com', Settings::mailRedirect()); } public function test_administrator_switches_the_mode_in_the_admin_and_sees_the_banner(): void { config(['fewo.mail_redirect_to' => null]); $this->landlord(); $this->actingAs(User::factory()->create()); $this->get(Operations::getUrl())->assertOk()->assertSee('Testbetrieb:'); Livewire::test(Operations::class) ->set('data.mode', Settings::MODE_TEST) ->set('data.test_recipient', 'lars@example.com') ->call('save') ->assertHasNoErrors(); $this->assertSame('lars@example.com', Settings::mailRedirect()); Livewire::test(Operations::class)->set('data.mode', Settings::MODE_LIVE)->call('save')->assertNotified('Scharf geschaltet'); $this->assertTrue(Settings::isLive()); $this->actingAs(User::factory()->role(UserRole::Rentals)->create()); $this->get(Operations::getUrl())->assertForbidden(); } /** * The only landlord, with the operating data under test applied to the configuration. * * @param array $attributes */ private function landlord(array $attributes = []): Tenant { $tenant = Tenant::factory()->create($attributes); app(TenantContext::class)->set($tenant); app(TenantConfig::class)->refresh(); return $tenant; } }