Loheide-eu-mitarbeiterplatt.../tests/Feature/Events/EventRegistrationTest.php
Friederich Loheide b293d2e05a
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m10s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 5m16s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m42s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m35s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m36s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m27s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m19s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
Terminanmeldung mit Plätzen und Warteliste (0.31.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 12:37:28 +00:00

109 lines
5.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Events;
use App\Models\User;
use App\Notifications\PortalNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Events\Models\Event;
use Inhaus\Plugins\Events\Models\EventRegistration;
use Tests\TestCase;
class EventRegistrationTest extends TestCase
{
use RefreshDatabase;
private function event(array $attributes = []): Event
{
return Event::factory()->create(['registration_enabled' => true, 'capacity' => 2, 'waitlist' => true, 'starts_at' => now()->addWeek(), ...$attributes]);
}
public function test_capacity_waitlist_and_moving_up(): void
{
Notification::fake();
$event = $this->event();
[$a, $b, $c, $d] = User::factory()->count(4)->create()->all();
$this->actingAs($a)->post("/termine/{$event->id}/anmeldung", ['note' => 'vegetarisch'])->assertRedirect()->assertSessionHas('status', 'Sie sind angemeldet.');
$this->actingAs($b)->post("/termine/{$event->id}/anmeldung");
$this->actingAs($c)->post("/termine/{$event->id}/anmeldung")->assertSessionHas('status', 'Der Termin ist ausgebucht – Sie stehen auf der Warteliste.');
$this->actingAs($d)->post("/termine/{$event->id}/anmeldung");
$this->actingAs($d)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page
->where('registration.status', 'waitlist')->where('registration.position', 2)
->where('registration.free', 0)->where('registration.waiting', 2)->where('participants', null));
$this->actingAs($a)->delete("/termine/{$event->id}/anmeldung")->assertRedirect();
$this->assertSame(EventRegistration::CONFIRMED, EventRegistration::query()->where('user_id', $c->id)->value('status'));
Notification::assertSentTo($c, PortalNotification::class, fn ($n) => str_contains($n->title, 'nachgerückt'));
Notification::assertNotSentTo($d, PortalNotification::class);
}
public function test_without_waitlist_a_full_event_rejects(): void
{
$event = $this->event(['capacity' => 1, 'waitlist' => false]);
[$a, $b] = User::factory()->count(2)->create()->all();
$this->actingAs($a)->post("/termine/{$event->id}/anmeldung");
$this->actingAs($b)->post("/termine/{$event->id}/anmeldung")->assertSessionHasErrors(['registration' => 'Der Termin ist leider ausgebucht.']);
}
public function test_deadline_and_disabled_registration(): void
{
$user = User::factory()->create();
$closed = $this->event(['registration_deadline' => now()->subHour()]);
$none = $this->event(['registration_enabled' => false]);
$this->actingAs($user)->post("/termine/{$closed->id}/anmeldung")->assertSessionHasErrors('registration');
$this->actingAs($user)->post("/termine/{$none->id}/anmeldung")->assertSessionHasErrors('registration');
$this->assertSame(0, EventRegistration::query()->count());
}
public function test_managers_see_the_list_export_and_raising_capacity_moves_people_up(): void
{
Notification::fake();
$admin = User::factory()->admin()->create();
$event = $this->event(['capacity' => 1]);
[$a, $b] = User::factory()->count(2)->create()->all();
$this->actingAs($a)->post("/termine/{$event->id}/anmeldung", ['note' => '=HYPERLINK("x")']);
$this->actingAs($b)->post("/termine/{$event->id}/anmeldung");
$this->actingAs($admin)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page->has('participants', 2)->where('participants.1.status', 'waitlist'));
$csv = $this->actingAs($admin)->get("/termine/{$event->id}/teilnehmende.csv")->assertOk()->streamedContent();
$this->assertStringContainsString("'=HYPERLINK", $csv);
$this->actingAs($a)->get("/termine/{$event->id}/teilnehmende.csv")->assertForbidden();
$this->actingAs($admin)->put("/redaktion/termine/{$event->id}", [
'title' => $event->title, 'starts_at' => $event->starts_at->format('Y-m-d\TH:i'), 'registration_enabled' => true, 'capacity' => 2, 'waitlist' => true,
])->assertSessionHasNoErrors();
$this->assertSame(2, EventRegistration::query()->where('status', EventRegistration::CONFIRMED)->count());
Notification::assertSentTo($b, PortalNotification::class);
}
public function test_public_participant_list_only_for_registered_people(): void
{
$event = $this->event(['participants_public' => true]);
[$a, $b] = User::factory()->count(2)->create()->all();
$this->actingAs($a)->post("/termine/{$event->id}/anmeldung", ['note' => 'geheim']);
$this->actingAs($b)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page->where('participants', null));
$this->actingAs($a)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page
->has('participants', 1)->where('participants.0.name', $a->name)->missing('participants.0.note'));
}
public function test_registration_via_api(): void
{
$user = User::factory()->create();
$event = $this->event();
$headers = ['Authorization' => 'Bearer '.$user->createToken('App')->plainTextToken];
$this->postJson("/api/v1/events/{$event->id}/registration", [], $headers)->assertOk()->assertJsonPath('data.status', 'confirmed');
$this->getJson("/api/v1/events/{$event->id}", $headers)->assertJsonPath('data.registration.status', 'confirmed');
$this->getJson('/api/v1/events', $headers)->assertJsonPath('data.0.registration.status', 'confirmed')->assertJsonPath('data.0.registration.enabled', true);
$this->deleteJson("/api/v1/events/{$event->id}/registration", [], $headers)->assertOk()->assertJsonPath('data.status', null);
}
}