Neuigkeiten und Termine (vorgezogen)
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 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>
This commit is contained in:
Friederich Loheide 2026-09-26 05:16:27 +00:00
parent f813a0fff3
commit a36752e09a
103 changed files with 2810 additions and 124 deletions

View file

@ -0,0 +1,84 @@
<?php
namespace Tests\Feature\Admin;
use App\Filament\Resources\Events\Pages\CreateEvent;
use App\Filament\Resources\NewsPosts\Pages\CreateNewsPost;
use App\Models\Event;
use App\Models\NewsCategory;
use App\Models\NewsPost;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class ContentAdminTest extends TestCase
{
use RefreshDatabase;
public function test_content_pages_are_reachable_for_admins_only(): void
{
$admin = User::factory()->admin()->create();
$post = NewsPost::factory()->create();
$event = Event::factory()->create();
foreach (['/admin/neuigkeiten', '/admin/neuigkeiten/neu', "/admin/neuigkeiten/{$post->id}/bearbeiten", '/admin/kategorien', '/admin/termine', '/admin/termine/neu', "/admin/termine/{$event->id}/bearbeiten"] as $url) {
$this->actingAs($admin)->get($url)->assertOk();
$this->actingAs(User::factory()->create())->get($url)->assertForbidden();
}
}
public function test_admin_can_write_a_post(): void
{
$admin = User::factory()->admin()->create();
$category = NewsCategory::factory()->create();
$this->actingAs($admin);
Livewire::test(CreateNewsPost::class)
->fillForm([
'title' => 'Neue Kantine eröffnet',
'teaser' => 'Ab Montag gibt es frisches Essen im Erdgeschoss.',
'category_id' => $category->id,
'published_at' => now()->subMinute()->format('Y-m-d H:i'),
])
->call('create')
->assertHasNoFormErrors();
$post = NewsPost::query()->firstOrFail();
$this->assertSame('neue-kantine-eroeffnet', $post->slug);
$this->assertSame($admin->id, $post->author_id);
$this->assertTrue($post->isPublished());
}
public function test_admin_can_create_an_event(): void
{
$this->actingAs(User::factory()->admin()->create());
Livewire::test(CreateEvent::class)
->fillForm([
'title' => 'Sommerfest',
'starts_at' => now()->addWeek()->format('Y-m-d 14:00'),
'ends_at' => now()->addWeek()->format('Y-m-d 18:00'),
'location' => 'Garten',
'is_published' => true,
])
->call('create')
->assertHasNoFormErrors();
$this->assertSame('Garten', Event::query()->firstOrFail()->location);
}
public function test_event_end_must_not_be_before_start(): void
{
$this->actingAs(User::factory()->admin()->create());
Livewire::test(CreateEvent::class)
->fillForm([
'title' => 'Falsch herum',
'starts_at' => now()->addWeek()->format('Y-m-d 14:00'),
'ends_at' => now()->addWeek()->format('Y-m-d 10:00'),
])
->call('create')
->assertHasFormErrors(['ends_at']);
}
}

View file

@ -0,0 +1,99 @@
<?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));
}
}

153
tests/Feature/NewsTest.php Normal file
View file

@ -0,0 +1,153 @@
<?php
namespace Tests\Feature;
use App\Models\NewsCategory;
use App\Models\NewsPost;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
class NewsTest extends TestCase
{
use RefreshDatabase;
public function test_only_published_posts_are_listed(): void
{
NewsPost::factory()->count(2)->create();
NewsPost::factory()->draft()->create();
NewsPost::factory()->scheduled()->create();
$this->actingAs(User::factory()->create())
->get('/neuigkeiten')
->assertOk()
->assertInertia(fn (Assert $page) => $page->component('News/Index')->where('posts.meta.total', 2));
}
public function test_posts_can_be_filtered_by_category(): void
{
$mav = NewsCategory::factory()->create(['name' => 'MAV', 'slug' => 'mav']);
NewsPost::factory()->create(['category_id' => $mav->id]);
NewsPost::factory()->count(2)->create();
$this->actingAs(User::factory()->create())
->get('/neuigkeiten?kategorie=mav')
->assertInertia(fn (Assert $page) => $page
->where('posts.meta.total', 1)
->where('posts.data.0.category.name', 'MAV')
->where('activeCategory', 'mav'));
}
public function test_published_post_is_shown_with_author(): void
{
$author = User::factory()->create(['first_name' => 'Grete', 'last_name' => 'Müller']);
$post = NewsPost::factory()->create(['author_id' => $author->id, 'title' => 'Sommerfest 2026']);
$this->assertSame('sommerfest-2026', $post->slug);
$this->actingAs(User::factory()->create())
->get('/neuigkeiten/sommerfest-2026')
->assertOk()
->assertInertia(fn (Assert $page) => $page
->component('News/Show')
->where('post.title', 'Sommerfest 2026')
->where('post.author.name', 'Grete Müller'));
}
public function test_drafts_and_scheduled_posts_are_not_reachable(): void
{
$draft = NewsPost::factory()->draft()->create();
$scheduled = NewsPost::factory()->scheduled()->create();
$user = User::factory()->create();
$this->actingAs($user)->get("/neuigkeiten/{$draft->slug}")->assertNotFound();
$this->actingAs($user)->get("/neuigkeiten/{$scheduled->slug}")->assertNotFound();
}
public function test_slugs_are_unique(): void
{
$a = NewsPost::factory()->create(['title' => 'Neuigkeit']);
$b = NewsPost::factory()->create(['title' => 'Neuigkeit']);
$this->assertSame('neuigkeit', $a->slug);
$this->assertSame('neuigkeit-2', $b->slug);
}
public function test_body_is_sanitized_when_saved(): void
{
$post = NewsPost::factory()->create([
'body' => '<p onclick="alert(1)">Hallo <strong>Welt</strong></p><script>alert(1)</script><a href="javascript:alert(1)">Link</a><iframe src="https://evil.example"></iframe>',
]);
$this->assertStringContainsString('<strong>Welt</strong>', $post->body_html);
$this->assertStringNotContainsString('script', $post->body_html);
$this->assertStringNotContainsString('onclick', $post->body_html);
$this->assertStringNotContainsString('javascript:', $post->body_html);
$this->assertStringNotContainsString('iframe', $post->body_html);
}
public function test_reading_time_is_calculated(): void
{
$post = NewsPost::factory()->create(['body' => '<p>'.str_repeat('Wort ', 450).'</p>']);
$this->assertSame(3, $post->reading_minutes);
}
public function test_cover_variants_are_created_and_removed(): void
{
Storage::fake('uploads');
Storage::disk('uploads')->put('news/cover.jpg', UploadedFile::fake()->image('cover.jpg', 2000, 1200)->getContent());
$post = NewsPost::factory()->create(['cover_path' => 'news/cover.jpg']);
Storage::disk('uploads')->assertExists('news/cover-thumb.webp');
Storage::disk('uploads')->assertExists('news/cover-large.webp');
$this->assertStringEndsWith('news/cover-thumb.webp', $post->coverUrl('thumb'));
$post->delete();
Storage::disk('uploads')->assertMissing('news/cover.jpg');
Storage::disk('uploads')->assertMissing('news/cover-thumb.webp');
}
public function test_large_photos_fit_into_shared_hosting_memory_limit(): void
{
Storage::fake('uploads');
// Testbild (12 Megapixel wie ein Handyfoto) mit großzügigem Limit erzeugen …
ini_set('memory_limit', '512M');
Storage::disk('uploads')->put('news/handyfoto.jpg', UploadedFile::fake()->image('handyfoto.jpg', 4000, 3000)->getContent());
gc_collect_cycles();
// … dann wie auf typischem Shared Hosting mit 128 MB verarbeiten.
$this->assertNotFalse(ini_set('memory_limit', '128M'));
NewsPost::factory()->create(['cover_path' => 'news/handyfoto.jpg']);
Storage::disk('uploads')->assertExists('news/handyfoto-large.webp');
Storage::disk('uploads')->assertExists('news/handyfoto-thumb.webp');
ini_set('memory_limit', '128M');
}
public function test_dashboard_shows_featured_and_latest_news(): void
{
Storage::fake('uploads');
Storage::disk('uploads')->put('news/a.jpg', UploadedFile::fake()->image('a.jpg', 800, 450)->getContent());
$featured = NewsPost::factory()->create(['is_featured' => true, 'cover_path' => 'news/a.jpg']);
NewsPost::factory()->count(5)->create();
NewsPost::factory()->draft()->create(['is_featured' => true, 'cover_path' => 'news/a.jpg']);
$this->actingAs(User::factory()->create())
->get('/')
->assertInertia(fn (Assert $page) => $page
->has('featuredNews.data', 1)
->where('featuredNews.data.0.id', $featured->id)
->has('latestNews.data', 4)
->has('moreNews.data', 1));
}
}

View file

@ -77,7 +77,7 @@ class PeopleDirectoryTest extends TestCase
->get('/personen')
->assertInertia(fn (Assert $page) => $page
->where('navigation.0.active', false)
->where('navigation.1.label', 'Personen')
->where('navigation.1.active', true));
->where('navigation.3.label', 'Personen')
->where('navigation.3.active', true));
}
}