Loheide-eu-mitarbeiterplatt.../tests/Feature/EventsTest.php
Friederich Loheide a36752e09a
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m8s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m5s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m6s
CI / Build-Artefakte aktuell (pull_request) Failing after 43s
Neuigkeiten und Termine (vorgezogen)
- Neuigkeiten mit Kategorien, Titelbild (WebP-Varianten), Lesezeit, geplanter
  Veröffentlichung und Hervorhebung; Text wird beim Speichern bereinigt
- Termine mit Ort, Online-Link, ganztägigen Terminen und .ics-Export
- Startseite nach Intranet-Vorbild: Slider, Neuigkeiten, Termine, Aktuelles
  aus den Bereichen; mobil in sinnvoller Reihenfolge
- Admin: Beiträge, Kategorien und Termine
- Bildverarbeitung für Shared Hosting: nur eine Vollbild-Kopie im Speicher,
  Speicherlimit bei Bedarf auf 256 MB angehoben (wie WordPress)
- Demo-Inhalte für die Entwicklung

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 05:16:27 +00:00

99 lines
4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Event;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
class EventsTest extends TestCase
{
use RefreshDatabase;
public function test_upcoming_and_running_events_are_listed_in_order(): void
{
$later = Event::factory()->create(['starts_at' => now()->addDays(10), 'ends_at' => now()->addDays(10)->addHour()]);
$soon = Event::factory()->create(['starts_at' => now()->addDay(), 'ends_at' => now()->addDay()->addHour()]);
$running = Event::factory()->create(['starts_at' => now()->subHour(), 'ends_at' => now()->addHour()]);
Event::factory()->create(['starts_at' => now()->subDays(3), 'ends_at' => now()->subDays(3)->addHour()]);
Event::factory()->create(['is_published' => false]);
$this->actingAs(User::factory()->create())
->get('/termine')
->assertOk()
->assertInertia(fn (Assert $page) => $page
->component('Events/Index')
->has('events.data', 3)
->where('events.data.0.id', $running->id)
->where('events.data.1.id', $soon->id)
->where('events.data.2.id', $later->id));
}
public function test_all_day_events_stay_visible_for_the_whole_day(): void
{
$today = Event::factory()->create(['starts_at' => now()->startOfDay(), 'ends_at' => null, 'all_day' => true]);
$this->actingAs(User::factory()->create())
->get('/termine')
->assertInertia(fn (Assert $page) => $page->where('events.data.0.id', $today->id));
}
public function test_event_detail_and_unpublished_events(): void
{
$event = Event::factory()->create(['title' => 'Betriebsfest']);
$hidden = Event::factory()->create(['is_published' => false]);
$user = User::factory()->create();
$this->actingAs($user)->get("/termine/{$event->id}")
->assertOk()
->assertInertia(fn (Assert $page) => $page->component('Events/Show')->where('event.title', 'Betriebsfest'));
$this->actingAs($user)->get("/termine/{$hidden->id}")->assertNotFound();
$this->actingAs($user)->get("/termine/{$hidden->id}/kalender.ics")->assertNotFound();
}
public function test_event_can_be_downloaded_as_ics(): void
{
$event = Event::factory()->create([
'title' => 'Teamschulung; Führung, Kommunikation',
'location' => 'Raum 1.04',
'starts_at' => '2026-10-05 10:00:00',
'ends_at' => '2026-10-05 15:00:00',
]);
$response = $this->actingAs(User::factory()->create())->get("/termine/{$event->id}/kalender.ics");
$response->assertOk()->assertHeader('Content-Type', 'text/calendar; charset=utf-8');
$ics = $response->getContent();
$this->assertStringStartsWith("BEGIN:VCALENDAR\r\n", $ics);
$this->assertStringContainsString('SUMMARY:Teamschulung\; Führung\, Kommunikation', $ics);
$this->assertStringContainsString('LOCATION:Raum 1.04', $ics);
$this->assertMatchesRegularExpression('/DTSTART:20261005T\d{6}Z/', $ics);
foreach (explode("\r\n", $ics) as $line) {
$this->assertLessThanOrEqual(75, strlen($line));
}
}
public function test_all_day_ics_uses_dates(): void
{
$event = Event::factory()->create(['starts_at' => '2026-11-11 00:00:00', 'ends_at' => null, 'all_day' => true]);
$ics = $this->actingAs(User::factory()->create())->get("/termine/{$event->id}/kalender.ics")->getContent();
$this->assertStringContainsString('DTSTART;VALUE=DATE:20261111', $ics);
$this->assertStringContainsString('DTEND;VALUE=DATE:20261112', $ics);
}
public function test_dashboard_shows_next_four_events(): void
{
Event::factory()->count(6)->create();
$this->actingAs(User::factory()->create())
->get('/')
->assertInertia(fn (Assert $page) => $page->has('upcomingEvents.data', 4));
}
}