New contact form with friendlycaptcha
This commit is contained in:
61
tests/Feature/ContactPageTest.php
Normal file
61
tests/Feature/ContactPageTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\Rule as ValidationRule;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use App\Mail\ContactFormSubmitted;
|
||||
|
||||
class ContactPageTest extends TestCase
|
||||
{
|
||||
public function test_contact_page_is_accessible()
|
||||
{
|
||||
$response = $this->get(route('contact'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee('Contactformulier');
|
||||
}
|
||||
|
||||
public function test_contact_form_can_be_submitted()
|
||||
{
|
||||
ValidationRule::macro('friendlycaptcha', function () {
|
||||
return new class implements Rule {
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'The :attribute is invalid.';
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Mail::fake();
|
||||
Storage::fake('public');
|
||||
|
||||
$image = UploadedFile::fake()->image('example.jpg');
|
||||
$video = UploadedFile::fake()->create('example.mp4', 1000, 'video/mp4');
|
||||
|
||||
$response = $this->post(route('contact.submit'), [
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
'message' => 'Dit is een testbericht.',
|
||||
'image' => $image,
|
||||
'video' => $video,
|
||||
'frc-captcha-solution' => 'dummy-solution',
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('contact'));
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
Mail::assertSent(function (ContactFormSubmitted $mail) {
|
||||
return $mail->hasTo('info@nhgooi.nl');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user