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:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 23:01:44 +02:00
1 parent fdcb68d578
commit d018c97be4
22 files changed
+698 -23

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
<?php
namespace Tests\Feature;
use App\Livewire\BookingRequest;
use App\Models\Booking;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Mail;
use Livewire\Features\SupportTesting\Testable;
use Livewire\Livewire;
use Tests\TestCase;
class SpamProtectionTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed(PropertySeeder::class);
Mail::fake();
}
public function test_form_sent_faster_than_a_human_is_ignored_silently(): void
{
$this->filled('anna@example.com')->call('submit')->assertHasNoErrors();
$this->assertSame(0, Booking::count());
}
public function test_honeypot_request_is_ignored(): void
{
$form = $this->filled('anna@example.com')->set('website', 'https://spam.example');
$this->travel(10)->seconds();
$form->call('submit');
$this->assertSame(0, Booking::count());
}
public function test_human_request_after_a_few_seconds_is_accepted(): void
{
$form = $this->filled('anna@example.com');
$this->travel(10)->seconds();
$form->call('submit')->assertHasNoErrors()->assertSee('Vielen Dank, Anna!');
$this->assertSame(1, Booking::count());
}
public function test_one_email_address_cannot_hold_many_dates_at_once(): void
{
foreach ([['2026-11-07', '2026-11-10'], ['2026-11-14', '2026-11-17'], ['2026-11-21', '2026-11-24']] as [$arrival, $departure]) {
$form = $this->filled('anna@example.com', $arrival, $departure);
$this->travel(10)->seconds();
$form->call('submit');
}
$this->assertSame(2, Booking::count());
}
public function test_links_in_names_or_many_links_in_the_message_are_rejected(): void
{
$form = $this->filled('anna@example.com')->set('firstName', 'Cheap https://pills.example')->set('message', 'see www.a.example and https://b.example');
$this->travel(10)->seconds();
$form->call('submit')->assertHasErrors(['firstName', 'message']);
$this->assertSame(0, Booking::count());
}
private function filled(string $email, string $arrival = '2026-11-07', string $departure = '2026-11-10'): Testable
{
return Livewire::test(BookingRequest::class)
->set('arrival', $arrival)
->set('departure', $departure)
->set('firstName', 'Anna')
->set('lastName', 'Muster')
->set('email', $email)
->set('privacyAccepted', true);
}
}