Operating mode in the admin (test mode sends all mail to a test recipient until switched live), bot protection for booking requests, mail rendering tests, mail:test command
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fdcb68d578
commit
d018c97be4
22 files changed
+698
-23
No files matched your search
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Pages\Operations;
|
||||
use App\Models\User;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Mail\MailManager;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OperationsModeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_new_installations_start_in_test_mode_with_the_notification_address(): void
|
||||
{
|
||||
config(['fewo.mail_redirect_to' => 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_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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user