Files
preregister/tests/Feature/StorePreregistrationPageTest.php

52 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\PageBlock;
use App\Models\PreregistrationPage;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class StorePreregistrationPageTest extends TestCase
{
use RefreshDatabase;
public function test_authenticated_user_can_store_page_without_files(): void
{
$user = User::factory()->create(['role' => 'user']);
$response = $this->actingAs($user)->post(route('admin.pages.store'), [
'title' => 'Summer Fest',
'thank_you_message' => null,
'expired_message' => null,
'ticketshop_url' => null,
'start_date' => '2026-06-01T10:00',
'end_date' => '2026-06-30T18:00',
'is_active' => true,
]);
$this->assertDatabaseCount('preregistration_pages', 1);
$page = PreregistrationPage::query()->first();
$response->assertRedirect(route('admin.pages.edit', $page));
$this->assertSame('Summer Fest', $page?->title);
$this->assertGreaterThanOrEqual(4, PageBlock::query()->where('preregistration_page_id', $page?->id)->count());
}
public function test_validation_failure_redirects_back_with_input(): void
{
$user = User::factory()->create(['role' => 'user']);
$response = $this->actingAs($user)->from(route('admin.pages.create'))->post(route('admin.pages.store'), [
'title' => '',
'start_date' => '2026-06-30T10:00',
'end_date' => '2026-06-01T10:00',
]);
$response->assertRedirect(route('admin.pages.create'));
$response->assertSessionHasErrors('title');
}
}