new updates
This commit is contained in:
69
tests/Feature/ContactFormSubmissionTest.php
Normal file
69
tests/Feature/ContactFormSubmissionTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use App\Mail\ContactFormSubmission;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use function Pest\Laravel\post;
|
||||
|
||||
afterEach(function () {
|
||||
Carbon::setTestNow();
|
||||
});
|
||||
|
||||
it('sends the contact form submission email and redirects to the localized thank-you page', function () {
|
||||
Mail::fake();
|
||||
|
||||
Carbon::setTestNow('2026-05-21 12:00:00');
|
||||
|
||||
$this->withSession(['contact_form_started_at' => now()->subSeconds(10)->timestamp]);
|
||||
|
||||
post('/sl/contact', [
|
||||
'name' => 'Gregor Test',
|
||||
'email' => 'gregor@example.com',
|
||||
'message' => "Hello from the website\nSecond line",
|
||||
'website' => '',
|
||||
])->assertRedirect('/sl/thankyou');
|
||||
|
||||
Mail::assertSent(ContactFormSubmission::class, function (ContactFormSubmission $mail) {
|
||||
return $mail->hasTo('office@aritmija.si')
|
||||
&& $mail->hasReplyTo('gregor@example.com')
|
||||
&& $mail->contactDetails['name'] === 'Gregor Test'
|
||||
&& $mail->contactDetails['email'] === 'gregor@example.com'
|
||||
&& $mail->contactDetails['message'] === "Hello from the website\nSecond line";
|
||||
});
|
||||
});
|
||||
|
||||
it('blocks submissions that arrive too quickly', function () {
|
||||
Mail::fake();
|
||||
|
||||
Carbon::setTestNow('2026-05-21 12:00:00');
|
||||
|
||||
$this->withSession(['contact_form_started_at' => now()->timestamp]);
|
||||
|
||||
post('/sl/contact', [
|
||||
'name' => 'Gregor Test',
|
||||
'email' => 'gregor@example.com',
|
||||
'message' => 'Fast bot message',
|
||||
'website' => '',
|
||||
])
|
||||
->assertSessionHasErrors('form');
|
||||
|
||||
Mail::assertNothingSent();
|
||||
});
|
||||
|
||||
it('blocks submissions that fill the honeypot field', function () {
|
||||
Mail::fake();
|
||||
|
||||
Carbon::setTestNow('2026-05-21 12:00:00');
|
||||
|
||||
$this->withSession(['contact_form_started_at' => now()->subSeconds(10)->timestamp]);
|
||||
|
||||
post('/sl/contact', [
|
||||
'name' => 'Gregor Test',
|
||||
'email' => 'gregor@example.com',
|
||||
'message' => 'Bot payload',
|
||||
'website' => 'https://spam.example',
|
||||
])
|
||||
->assertSessionHasErrors('website');
|
||||
|
||||
Mail::assertNothingSent();
|
||||
});
|
||||
Reference in New Issue
Block a user