null, 'fewo.notification_email' => 'fewo@example.com']); $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']); Settings::save([Settings::MODE => Settings::MODE_TEST, Settings::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']); Settings::save([Settings::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_of_the_internal_communication_are_set_in_the_admin(): void { config(['fewo.mail_redirect_to' => null]); $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') ->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')]); Mail::fake(); $this->seed(PropertySeeder::class); $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_invalid_notification_addresses_are_rejected(): void { $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']); Settings::save([Settings::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->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(); } }