- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Form;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class FormSubmissionTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_can_submit_form(): void
|
|
{
|
|
$form = Form::create([
|
|
'name' => 'Contact',
|
|
'slug' => 'contact',
|
|
'fields' => [['name' => 'email', 'type' => 'email']],
|
|
]);
|
|
|
|
$response = $this->post(route('forms.submit', $form->slug), [
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$response->assertStatus(302); // Redirect back
|
|
$this->assertDatabaseHas('form_submissions', [
|
|
'form_id' => $form->id,
|
|
'data' => json_encode(['email' => 'test@example.com']),
|
|
]);
|
|
}
|
|
|
|
public function test_can_submit_form_via_json(): void
|
|
{
|
|
$form = Form::create([
|
|
'name' => 'Contact',
|
|
'slug' => 'contact',
|
|
'fields' => [['name' => 'email', 'type' => 'email']],
|
|
]);
|
|
|
|
$response = $this->postJson(route('forms.submit', $form->slug), [
|
|
'email' => 'test@example.com',
|
|
]);
|
|
|
|
$response->assertStatus(200);
|
|
$response->assertJson(['success' => true]);
|
|
}
|
|
}
|