get('https://pressekonto.test/')->assertSuccessful(); $content = $response->getContent(); expect($content) ->not->toContain('Vertrag widerrufen') ->not->toContain('open-withdrawal-modal'); }); test('a withdrawal is persisted and both mails are queued after persistence', function () { /** @var TestCase $this */ Mail::fake(); config()->set('domains.domains.pressekonto.brand.contact_email', 'kontakt@pressekonto.de'); $this->from('https://pressekonto.test/') ->post('https://pressekonto.test/widerruf', [ 'name' => 'Paula Presse', 'email' => 'paula@example.test', 'order_reference' => 'STR-2026-0042', ]) ->assertRedirect('https://pressekonto.test/') ->assertSessionHas('withdrawal-status'); $request = WithdrawalRequest::query()->firstOrFail(); expect($request->name)->toBe('Paula Presse'); expect($request->email)->toBe('paula@example.test'); expect($request->order_reference)->toBe('STR-2026-0042'); expect($request->host)->toBe('pressekonto.test'); expect($request->status)->toBe('open'); // Gesetzlich vorgeschrieben: sofortige automatische Eingangsbestätigung. Mail::assertQueued(WithdrawalRequestReceived::class, fn (WithdrawalRequestReceived $mail) => $mail->hasTo('paula@example.test')); Mail::assertQueued(WithdrawalRequestSubmitted::class, fn (WithdrawalRequestSubmitted $mail) => $mail->hasTo('kontakt@pressekonto.de')); }); test('the order reference is optional', function () { /** @var TestCase $this */ Mail::fake(); $this->post('https://pressekonto.test/widerruf', [ 'name' => 'Paula Presse', 'email' => 'paula@example.test', ])->assertSessionHas('withdrawal-status'); expect(WithdrawalRequest::query()->firstOrFail()->order_reference)->toBeNull(); }); test('withdrawal validation errors land in the withdrawal error bag', function () { /** @var TestCase $this */ Mail::fake(); $this->post('https://pressekonto.test/widerruf', [ 'name' => '', 'email' => 'keine-mail', ])->assertSessionHasErrorsIn('withdrawal', ['name', 'email']); expect(WithdrawalRequest::query()->count())->toBe(0); Mail::assertNothingOutgoing(); }); test('honeypot submissions are silently accepted without persisting or mailing', function () { /** @var TestCase $this */ Mail::fake(); $this->post('https://pressekonto.test/widerruf', [ 'name' => 'Bot', 'email' => 'bot@example.test', 'website' => 'https://spam.example', ])->assertSessionHas('withdrawal-status'); expect(WithdrawalRequest::query()->count())->toBe(0); Mail::assertNothingOutgoing(); }); test('a withdrawal from a spoke domain goes to that brand address', function () { /** @var TestCase $this */ Mail::fake(); config()->set('domains.domains.presseecho.brand.contact_email', 'redaktion@presseecho.de'); $this->post('https://presseecho.test/widerruf', [ 'name' => 'Paula Presse', 'email' => 'paula@example.test', ])->assertSessionHas('withdrawal-status'); Mail::assertQueued(WithdrawalRequestSubmitted::class, fn (WithdrawalRequestSubmitted $mail) => $mail->hasTo('redaktion@presseecho.de')); });